Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: gcc broke

Reply
Thread Tools

Re: gcc broke

 
 
jacob navia
Guest
Posts: n/a
 
      11-15-2009
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?
 
Reply With Quote
 
 
 
 
Nick
Guest
Posts: n/a
 
      11-15-2009
jacob navia <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      11-17-2009
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!
 
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
Re: gcc broke Keith Thompson C Programming 2 11-16-2009 06:02 PM
Re: gcc broke Eric Sosman C Programming 0 11-15-2009 10:13 PM
Template construction in old gcc 3.3.3 does not compile in gcc 3.4.4 eknecronzontas@yahoo.com C++ 5 09-17-2005 12:27 AM
gcc 2.95 and gcc 3.2 gouqizi.lvcha@gmail.com C++ 8 03-16-2005 02:34 AM
C99 structure initialization in gcc-2.95.3 vs gcc-3.3.1 Kevin P. Fleming C Programming 2 11-06-2003 05:15 AM



Advertisments