Re: gcc broke

Discussion in 'C Programming' started by jacob navia, Nov 15, 2009.

  1. jacob navia

    jacob navia Guest

    Malcolm McLean a écrit :
    > foo.c
    >
    > #include <stdio.h>
    >
    > static char *getline(FILE *fp);
    >
    >
    > static char *getline(FILE *fp)
    > {
    > /* does what you think it does */
    > }
    >
    > gcc *.c -lm.
    >
    > Warning getline multiply defined. Other defintion in stdio.h.
    > Links, and crashes on running. Obviously the bad getline is called.
    >
    > The only fix is to make the program uncompileable except by a skilled user,
    > or the change getline to xgetline.
    >


    Another fix that will probably work is to force it to respect the
    implementation namespace: use -std=c99 or -std=c89. I suppose that
    will work.

    > The worst thing is that they changed the version of the compiler on me
    > suddenly.
    > Why do people always have to make changes to the way programs work?
    >


    In the company I work for, gcc made the code no longer compilable with the new
    version. (3.xx to 4.xx)

    Templates were defined at some place, but only checked when actually used.

    That way, the order of the includes didn't make any difference. All symbols
    must be defined only when the template is expanded.

    In the new version, it tested if all symbols are defined when the template
    was defined. The order of includes DID make a HUGE difference. And there
    we went, approximately 1 man month of work to test it in the different versions
    seeing if the changes did not introduce new bugs, etc etc.

    When I reported that, they told me that I was "using illegal C++".

    The fact that their compiler happily compiled that did not bother them

    > It also gives stupid warnings about ignoring the return from fgets(). So the
    > real warning will be buried, unless you are careful.


    ??? Why does it give that warning?
     
    jacob navia, Nov 15, 2009
    #1
    1. Advertising

  2. jacob navia

    Nick Guest

    jacob navia <> writes:

    > In the company I work for, gcc made the code no longer compilable with the new
    > version. (3.xx to 4.xx)
    >
    > Templates were defined at some place, but only checked when actually used.
    >
    > That way, the order of the includes didn't make any difference. All symbols
    > must be defined only when the template is expanded.
    >
    > In the new version, it tested if all symbols are defined when the template
    > was defined. The order of includes DID make a HUGE difference. And there
    > we went, approximately 1 man month of work to test it in the different versions
    > seeing if the changes did not introduce new bugs, etc etc.
    >
    > When I reported that, they told me that I was "using illegal C++".
    >
    > The fact that their compiler happily compiled that did not bother them


    That is, of course, why so many people here say "it doesn't matter that
    your compiler compiled it and it worked, it's not good C". Because if
    it had been, you'd have had a comeback against this, but as it wasn't,
    you don't.
    --
    Online waterways route planner: http://canalplan.org.uk
    development version: http://canalplan.eu
     
    Nick, Nov 15, 2009
    #2
    1. Advertising

  3. jacob navia

    Flash Gordon Guest

    jacob navia wrote:
    > Malcolm McLean a écrit :
    >> foo.c
    >>
    >> #include <stdio.h>
    >>
    >> static char *getline(FILE *fp);
    >>
    >>
    >> static char *getline(FILE *fp)
    >> {
    >> /* does what you think it does */
    >> }
    >>
    >> gcc *.c -lm.
    >>
    >> Warning getline multiply defined. Other defintion in stdio.h.
    >> Links, and crashes on running. Obviously the bad getline is called.
    >>
    >> The only fix is to make the program uncompileable except by a skilled
    >> user, or the change getline to xgetline.

    >
    > Another fix that will probably work is to force it to respect the
    > implementation namespace: use -std=c99 or -std=c89. I suppose that
    > will work.


    To guarantee it you might also need -pedantic, but yes, basically, if
    you want to use functions which clash with extensions you may well need
    to force the compiler in to conforming mode. That is one reason
    compilers *have* conforming modes, so you can do this!

    >> The worst thing is that they changed the version of the compiler on me
    >> suddenly.
    >> Why do people always have to make changes to the way programs work?
    >>

    >
    > In the company I work for, gcc made the code no longer compilable with
    > the new
    > version. (3.xx to 4.xx)


    It happens.

    > Templates were defined at some place, but only checked when actually used.
    >
    > That way, the order of the includes didn't make any difference. All symbols
    > must be defined only when the template is expanded.
    >
    > In the new version, it tested if all symbols are defined when the template
    > was defined. The order of includes DID make a HUGE difference. And there
    > we went, approximately 1 man month of work to test it in the different
    > versions
    > seeing if the changes did not introduce new bugs, etc etc.
    >
    > When I reported that, they told me that I was "using illegal C++".
    >
    > The fact that their compiler happily compiled that did not bother them


    From what you say, the fact that the old compiler happily compiled it
    was a bug in the old compiler, one they fixed in the new version. This,
    quite simply, is one reason why you need to know what guarantees the
    relevant standards provide, force your compiler in to as close to
    standards mode as you can (whilst still meeting other requirements, such
    as having access to extensions you actually need), and only use
    non-standard facilities when you need them. Any extension you use could
    be broken on a major compiler release!

    >> It also gives stupid warnings about ignoring the return from fgets().
    >> So the real warning will be buried, unless you are careful.

    >
    > ??? Why does it give that warning?


    Probably because it was enabled. Although I have to say that fgets is
    one of the functions where you *should* check the return value!
     
    Flash Gordon, Nov 17, 2009
    #3
    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. Replies:
    8
    Views:
    432
  2. Kevin P. Fleming

    C99 structure initialization in gcc-2.95.3 vs gcc-3.3.1

    Kevin P. Fleming, Nov 6, 2003, in forum: C Programming
    Replies:
    2
    Views:
    646
    Kevin P. Fleming
    Nov 6, 2003
  3. Replies:
    5
    Views:
    362
    Nathan Addy
    Sep 17, 2005
  4. Eric Sosman

    Re: gcc broke

    Eric Sosman, Nov 15, 2009, in forum: C Programming
    Replies:
    0
    Views:
    418
    Eric Sosman
    Nov 15, 2009
  5. Keith Thompson

    Re: gcc broke

    Keith Thompson, Nov 15, 2009, in forum: C Programming
    Replies:
    2
    Views:
    427
    Keith Thompson
    Nov 16, 2009
Loading...

Share This Page