Never realised this was dodgy before...

P

Phil Carmody

#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

Ian Collins

#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.
 
S

Seebs

#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
 
P

Paul N

#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.
 
E

Eric Sosman

#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?
 
P

Peter Nilsson

Carmody said:
#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.
 
P

Phil Carmody

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

<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,
Phil
 
D

Default User

Paul said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top