global vars and symbol visibility for mips32/elf
Jim Wilson
wilson@chestnut.cygnus.com
Tue Aug 13 13:36:00 GMT 1996
Wrong. A standard conforming compiler will conclaim about a multiply
defined symbol.
This is not correct. You have missed a subtle point here.
A program that has multiple external definitions is not a strictly conforming
program. If you want your programs to be strictly conforming, then you can not
rely on common.
A conforming compiler must accept any strictly conforming program. However, a
conforming compiler can have extensions that allow it to accept non-strictly
conforming programs providing that such extensions do not change the behaviour
of any strictly conforming program.
The standard says that a program with multiple external definitions results
in undefined behaviour. A standard conforming compiler can do anything when
an input program triggers undefined behaviour. Normally, we give a warning
to encourage portable programming. In this particular case, gcc chooses to
have an extensions that allows such programs to work.
This extension is even sanctioned by the standard (in a sense), as it is
documented in the section on common extensions.
A very similar case is identifier names. Consider this program:
int abcdef1;
int abcdef2;
This is not a strictly conforming program. The standard says that only
the first 6 characters are guaranteed to be significant, and it is
implementation defined whether any characters after the first 6 are used.
Gcc however accepts this program without complaint, and it would be very
unwise to change this. In this case, we do not want to enforce the strict
limits of the standard, because that is far too inconvenient for programmers.
It is debatable whether multiple external definitions deserves the same
treatment. It is not a bug in gcc that it accepts them though.
Jim
More information about the Gas2
mailing list