Never realised this was dodgy before...

Discussion in 'C Programming' started by Phil Carmody, Mar 30, 2010.

  1. Phil Carmody

    Phil Carmody Guest

    #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
     
    Phil Carmody, Mar 30, 2010
    #1
    1. Advertising

  2. Phil Carmody

    Ian Collins Guest

    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
     
    Ian Collins, Mar 30, 2010
    #2
    1. Advertising

  3. Phil Carmody

    Seebs Guest

    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 /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
     
    Seebs, Mar 30, 2010
    #3
  4. Phil Carmody

    Paul N Guest

    On 30 Mar, 21:25, 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.


    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.
     
    Paul N, Mar 30, 2010
    #4
  5. Phil Carmody

    Eric Sosman Guest

    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
     
    Eric Sosman, Mar 30, 2010
    #5
  6. 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.


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

    --
    Peter
     
    Peter Nilsson, Mar 31, 2010
    #6
  7. Phil Carmody

    Phil Carmody Guest

    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
     
    Phil Carmody, Mar 31, 2010
    #7
  8. Phil Carmody

    Default User Guest

    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
     
    Default User, Mar 31, 2010
    #8
  9. Phil Carmody

    Noob Guest

    Noob, Apr 1, 2010
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adam Knight

    Dodgy Nested Grid Update!

    Adam Knight, Aug 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    405
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Aug 9, 2005
  2. Replies:
    2
    Views:
    368
  3. Tomás

    Just a dodgy compiler?

    Tomás, Mar 3, 2006, in forum: C++
    Replies:
    8
    Views:
    408
    Alf P. Steinbach
    Mar 3, 2006
  4. voidtwerp
    Replies:
    2
    Views:
    347
    Daniel T.
    May 23, 2006
  5. Marc-André Cournoyer

    [ANN] Thin 0.8.0 Dodgy Dentist release

    Marc-André Cournoyer, Apr 6, 2008, in forum: Ruby
    Replies:
    0
    Views:
    104
    Marc-André Cournoyer
    Apr 6, 2008
Loading...

Share This Page