Is this a bug in gcc??

Martin York
Wed Dec 1 15:09:00 GMT 2004

 Name lastlong wrote:
> Hi,
> I am expecting a error (redefinition of "a") from following piece of 
> code. But gcc (3.4.2) doesnot give any error.
> /////////////////
> int a;
> char b;
> int a;

Just to expand on what has already been said.
gcc/g++ behave as required by the standard. But to make sure we compare
apples to apples.

If you add the above to the file: test.c

gcc -c test.c   # Works Fine     (as expected)
g++ -c test.c   # Outputs errors (as expected)

Note that gcc is a C compiler (or should I say invokes the underlying C
Compiler by default) while g++ is a C++ compiler. NB If you name the
file test.cpp the content is C++ and the C++ compiler will be invoked no
matter how 'Gcc' is invoked (unless you explicitly override the

More information about the Gcc-help mailing list