"Ben Bacarisse" <> wrote in message
news:...
> jacob navia <> writes:
> <snip>
>> This can be tested, for instance, with the following two files:
>> file t1.c
>> int tab[12];
>>
>> File t2.c
>> int tab[256];
>> int main(void){return 0;}
>>
>> Linking t1.c and t2.c with MSVC 8 we obtain an executable *without any
>> warnings* not even at the highest warning level.
>>
>> In the linker of lcc-win I added a warning:
>> in t1.obj warning: '_tab' (defined with size 4
>> is redefined in t2.obj with size 1024
>>
>> The linker of gnu doesn't emit any warning:
>> root@ubuntu:/tmp# gcc -Wall t1.c t2.c
>
> *Please* post these articles in comp.programming. I'd join in a lot
> more if I could do so and be topical. However, you are dead set on
> knocking gcc without understanding it so...
>
> <off-topic>
> gcc uses the GNU linker ld. ld merges the common blocks to make tab
> the larger of the two size regardless of the linking order. In this
> case, I can't see why you'd want a diagnostic[1]. When a compilation
> unit initialises the table (so it can't be merged) the GNU linker
> *does* produce a warning:
>
> /usr/bin/ld: Warning: size of symbol `tab' changed from 1024 in t1.o
> to 16 in t2.o
> </off-topic>
>
> <snip>
>> Next installment will treat the object libraries
>
> Please post it where it belongs.
>
> [1] OK, a case can be made for a diagnostic in all such cases, but you
> are suggesting the gcc leads the programmer silently into a trap.
C:\tmp>splint t1.c t2.c
Splint 3.1.1 --- 12 Mar 2007
t2.c(2,5): Variable tab redefined
A function or variable is redefined. One of the declarations should use
extern. (Use -redef to inhibit warning)
t1.c(2,5): Previous definition of tab
Finished checking --- 1 code warning
C:\tmp>lin t1.c t2.c
C:\tmp>"C:\Lint\Lint-nt" +v -i"C:\Lint" std.lnt -os(_LINT.TMP) t1.c t2.c
PC-lint for C/C++ (NT) Vers. 8.00u, Copyright Gimpel Software 1985-2006
--- Module: t1.c (C)
--- Module: t2.c (C)
C:\tmp>type _LINT.TMP | more
--- Module: t1.c (C)
--- Module: t2.c (C)
_
int tab[256];
t2.c(2) : Error 18: Symbol 'tab' redeclared (size) conflicts with line 2,
file
t1.c
t1.c(2) : Info 830: Location cited in prior message
_
int tab[256];
t2.c(2) : Error 14: Symbol 'tab' previously defined (line 2, file t1.c)
t1.c(2) : Info 830: Location cited in prior message
--- Global Wrap-up
Info 765: external 'tab' (line 2, file t1.c) could be made static
t1.c(2) : Info 830: Location cited in prior message
Warning 552: Symbol 'tab' (line 2, file t1.c) not accessed
t1.c(2) : Info 830: Location cited in prior message
---
output placed in _LINT.TMP
C:\tmp>type t1.c
/* file t1.c */
int tab[12];
C:\tmp>type t2.c
/* File t2.c */
int tab[256];
int main(void){tab[25] = 0; return 0;}
P.S.
There are plenty of instances of undefined behavior not caught by compilers.
P.P.S.
I do agree that it would be nice if compilers were omniscient (or closer
than they are today).
--
Posted via a free Usenet account from
http://www.teranews.com