This is the mail archive of the gas2@sourceware.cygnus.com mailing list for the gas2 project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
On Tue, 13 Aug 1996, Jim Wilson wrote:
> 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.
But the standard allows such behaviour only if no strictly
standard-conforming program is broken by the extension. The following
program is strictly conforming and should continue to run:
#include <assert.h>
int optind[30000], optarg[30000];
main()
{
int i;
for (i = 0; i < 30000; i++) {
optind[i] = 1;
optarg[i] = 2;
}
for (i = 0; i < 30000; i++) {
assert(optind[i] == 1);
assert(optarg[i] == 2);
}
return 0;
}
Try this to see whether your compiler conforms to the C standard!
Ruediger Helsch <rh@unifix.de>