This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC:patch] c99 6.2.2: static vs extern


DJ Delorie <dj@redhat.com> writes:

| Consider this test program:
| 
| static int a = 10;
| extern void foo(int);
| 
| int main(void)
| {
|  extern int a;
| 
|  foo(a);
| 
|  return 0;
| }
| 
| The ISO/IEC 9899:1999 standard section 6.2.2 paragraph 4 seems to
| require that the "extern" above does not override the "static" at
| global scope:
| 
|   For an identifier declared with the storage-class specifier extern
|   in a scope in which a prior declaration of that identifier is
|   visible, if the prior declaration specifies internal or external
|   linkage, the linkage of the identifier at the later declaration is
|   the same as the linkage specified at the prior declaration.

Yes.  Otherwise, there would be no way to say that the "a" in main()
is referring to the a at file scope.  Whether that is a good style is
a different matter; but that is what the C standard says.

| An obvious patch is attached, but I'm unsure if it's right for
| two reasons:
| 
| 1. There may be subtle side effects of allowing this type of
|    declaration without voiding it, and
| 
| 2. I'm unsure about which controlling option(s) and default we want
|    for this case.

I think this has always been the case -- at least in C90.  I don't
think you should be controling with !flag_isoc99.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]