Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Never realised this was dodgy before...

Reply
Thread Tools

Never realised this was dodgy before...

 
 
Phil Carmody
Guest
Posts: n/a
 
      03-30-2010
#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
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      03-30-2010
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
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      03-30-2010
On 2010-03-30, Phil Carmody <> 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-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Paul N
Guest
Posts: n/a
 
      03-30-2010
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.

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      03-30-2010
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
lid
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      03-31-2010
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
 
Reply With Quote
 
Phil Carmody
Guest
Posts: n/a
 
      03-31-2010
Eric Sosman <> writes:
> 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?


<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
--
I find the easiest thing to do is to k/f myself and just troll away
-- David Melville on r.a.s.f1
 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      03-31-2010
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
 
Reply With Quote
 
Noob
Guest
Posts: n/a
 
      04-01-2010
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....2?dmode=source
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
You've never seen it before and you'll never see it again. Fred A Stover Computer Support 7 12-26-2007 03:33 AM
XML Schema never-never occurence of declared elements / attributes Soren Kuula XML 1 12-01-2005 01:27 PM
string routines go to never never land on unix Kevin C Programming 4 10-17-2003 06:07 PM
Will this Broadband dream ever be realised in NZ? Rats NZ Computing 11 09-09-2003 06:58 PM
Re: Win98 CD is NOT bootable! never was-never will be :-) Andrew Tang A+ Certification 0 07-05-2003 08:23 AM



Advertisments