Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Never realised this was dodgy before...

2 views
Skip to first unread message

Phil Carmody

unread,
Mar 30, 2010, 4:25:20 PM3/30/10
to
#include <stdio.h>
void do_stuff(FILE **pfp) { fputs("did something!\n", *pfp); }
void get_stuff_done(void) { do_stuff(&stdin); }

GCC's no help (spoiler*epsilon: then again, given the dodginess, I can't
imagine how it would detect it without unacceptable overheads):
phil@duospaz:tmp$ gcc -ansi -pedantic -Wall -Wextra -c crap.c
phil@duospaz:tmp$ gcc -std=c99 -Wall -Wextra -c crap.c
phil@duospaz:tmp$

Was I slow?

No point leaving you on the hook unnecessarily. Gentle and complete
spoilers both in headers.

Phil
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1

Ian Collins

unread,
Mar 30, 2010, 4:47:43 PM3/30/10
to
On 03/31/10 09:25 AM, Phil Carmody wrote:
> #include<stdio.h>
> void do_stuff(FILE **pfp) { fputs("did something!\n", *pfp); }
> void get_stuff_done(void) { do_stuff(&stdin); }
>
> GCC's no help (spoiler*epsilon: then again, given the dodginess, I can't
> imagine how it would detect it without unacceptable overheads):
> phil@duospaz:tmp$ gcc -ansi -pedantic -Wall -Wextra -c crap.c
> phil@duospaz:tmp$ gcc -std=c99 -Wall -Wextra -c crap.c
> phil@duospaz:tmp$
>
> Was I slow?

No, your platform was unhelpful in its definition!

c99 /tmp/x.c
"/tmp/x.c", line 3: unacceptable operand for unary &

gcc /tmp/x.c
/tmp/x.c: In function 'get_stuff_done':
/tmp/x.c:3: error: invalid lvalue in unary '&'

> No point leaving you on the hook unnecessarily. Gentle and complete
> spoilers both in headers.

Cool comments!

I'll follow up with the Solaris definitions if anyone's interested.

--
Ian Collins

Seebs

unread,
Mar 30, 2010, 5:28:10 PM3/30/10
to
On 2010-03-30, Phil Carmody <thefatphi...@yahoo.co.uk> wrote:
> #include <stdio.h>
> void do_stuff(FILE **pfp) { fputs("did something!\n", *pfp); }
> void get_stuff_done(void) { do_stuff(&stdin); }

Ooh, sneaky. If "stdin" isn't actually an object of type "FILE *",
but an expression yielding one, it can indeed be invalid to take its
address. That would not have occurred to me.

I do actually have a hunk of code floating around which uses a FILE **,
but it operates only on the addresses of FILE * objects I've declared
myself.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Paul N

unread,
Mar 30, 2010, 5:40:18 PM3/30/10
to
On 30 Mar, 21:25, Phil Carmody <thefatphil_demun...@yahoo.co.uk>
wrote:

> #include <stdio.h>
> void do_stuff(FILE **pfp) { fputs("did something!\n", *pfp); }
> void get_stuff_done(void) { do_stuff(&stdin); }
>
> GCC's no help (spoiler*epsilon: then again, given the dodginess, I can't
> imagine how it would detect it without unacceptable overheads):
> phil@duospaz:tmp$ gcc -ansi -pedantic -Wall -Wextra -c crap.c
> phil@duospaz:tmp$ gcc -std=c99 -Wall -Wextra -c crap.c
> phil@duospaz:tmp$
>
> Was I slow?
>
> No point leaving you on the hook unnecessarily. Gentle and complete
> spoilers both in headers.

I'm reading this in Google groups, and have no idea how to "read the
headers" or whether this is even possible. Could you put the comments
somewhere I can read them, please?

Thanks.
Paul.

Eric Sosman

unread,
Mar 30, 2010, 5:43:58 PM3/30/10
to
On 3/30/2010 4:25 PM, Phil Carmody wrote:
> #include<stdio.h>
> void do_stuff(FILE **pfp) { fputs("did something!\n", *pfp); }
> void get_stuff_done(void) { do_stuff(&stdin); }
>
> GCC's no help (spoiler*epsilon: then again, given the dodginess, I can't
> imagine how it would detect it without unacceptable overheads):
> phil@duospaz:tmp$ gcc -ansi -pedantic -Wall -Wextra -c crap.c
> phil@duospaz:tmp$ gcc -std=c99 -Wall -Wextra -c crap.c
> phil@duospaz:tmp$
>
> Was I slow?
>
> No point leaving you on the hook unnecessarily. Gentle and complete
> spoilers both in headers.

There's also the tiny matter of attempting output on the
standard input stream. Been abusing freopen(), have we?

--
Eric Sosman
eso...@ieee-dot-org.invalid

Peter Nilsson

unread,
Mar 30, 2010, 8:11:11 PM3/30/10
to
Carmody <thefatphil_demun...@yahoo.co.uk> wrote:
> #include <stdio.h>
> void do_stuff(FILE **pfp) { fputs("did something!\n", *pfp); }
> void get_stuff_done(void) { do_stuff(&stdin); }
>
> GCC's no help (spoiler*epsilon: then again, given the dodginess,
> I can't imagine how it would detect it without unacceptable
> overheads):
> phil@duospaz:tmp$ gcc -ansi -pedantic -Wall -Wextra -c crap.c
> phil@duospaz:tmp$ gcc -std=c99 -Wall -Wextra -c crap.c
> phil@duospaz:tmp$
>
> Was I slow?
>
> No point leaving you on the hook unnecessarily. Gentle and complete
> spoilers both in headers.

C++ users who've tried std::stdin often become quickly aware that
stdin is actually a macro.

--
Peter

Phil Carmody

unread,
Mar 31, 2010, 4:33:50 AM3/31/10
to

<Unruffle> freopen exists exactly for that reason, so it's
not 'abuse' at all!

Good catch; that was completely accidental. I'm glad that the
real dodginess I was referring to was still visible behind that.

Cheers,

Default User

unread,
Mar 31, 2010, 2:01:52 PM3/31/10
to
Paul N wrote:

> I'm reading this in Google groups, and have no idea how to "read the
> headers" or whether this is even possible. Could you put the comments
> somewhere I can read them, please?

Click "more options", then "show original".

Brian

--
Day 420 of the "no grouchy usenet posts" project

Noob

unread,
Apr 1, 2010, 9:57:05 AM4/1/10
to
Paul N wrote:

> Phil Carmody wrote:
>
>> No point leaving you on the hook unnecessarily. Gentle and complete
>> spoilers both in headers.
>
> I'm reading this in Google groups, and have no idea how to "read the
> headers" or whether this is even possible.

??

http://groups.google.com/group/comp.lang.c/msg/4b566d77d29182f2?dmode=source

0 new messages