Topic: A nasty inconsistancy in `extern "C"' linkage.


Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Sun, 25 Sep 1994 21:32:23 GMT
Raw View
Am I the first person who ever noticed that:

 extern "C" int foo;

and

 extern "C" { int foo; }

are NOT semantically equivalent??

Surely this annoying inconsistancy must have caught _someone_ else's
attention before now!

--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- domain addr: rfg@netcom.com ----------- Purveyors of Compiler Test ----
---- uucp addr: ...!uunet!netcom!rfg ------- Suites and Bullet-Proof Shoes -




Author: jason@cygnus.com (Jason Merrill)
Date: Sun, 25 Sep 1994 23:11:57 GMT
Raw View
>>>>> Ronald F Guilmette <rfg@netcom.com> writes:

> Am I the first person who ever noticed that:
>  extern "C" int foo;

> and

>  extern "C" { int foo; }

> are NOT semantically equivalent??

> Surely this annoying inconsistancy must have caught _someone_ else's
> attention before now!

The first is currently consisten with "extern int foo;", which I think is
appropriate.  The second cannot automatically make everything in it extern;
if it did, static variables in header files would break.

Hmm.  Now that we have namespaces, it would seem appropriate to subsume the
functionality of extern "C" { } into some sort of special namespace and
deprecate the old form.

Jason




Author: rubenst%occs.nlm.nih.gov (Michael M. Rubenstein)
Date: Mon, 26 Sep 94 16:26:02 GMT
Raw View
Ronald F. Guilmette (rfg@netcom.com) wrote:
> Am I the first person who ever noticed that:

>  extern "C" int foo;

> and

>  extern "C" { int foo; }
>
> are NOT semantically equivalent??

> Surely this annoying inconsistancy must have caught _someone_ else's
> attention before now!

You're not the first to notice this:

 [The semantics extern "C" { ... }] implies that

  extern "C" { /* ... */ }

 can be used without changing the semantics of the enclosed object
 definitions, but it has the peculiar effect that the declarations

  extern "C" {
   int a1;
  }

 and

  extern "C" int a2;

 are not equivalent.  Here a1 is defined and a2 is only declared.

  ARM 7.4

--
Mike Rubenstein




Author: rfg@netcom.com (Ronald F. Guilmette)
Date: Tue, 27 Sep 1994 09:25:27 GMT
Raw View
In article <JASON.94Sep25161157@deneb.cygnus.com> jason@cygnus.com (Jason Merrill) writes:
>>>>>> Ronald F Guilmette <rfg@netcom.com> writes:
>
>> Am I the first person who ever noticed that:
>>  extern "C" int foo;
>
>> and
>
>>  extern "C" { int foo; }
>
>> are NOT semantically equivalent??
>
>> Surely this annoying inconsistancy must have caught _someone_ else's
>> attention before now!
>
>The first is currently consisten with "extern int foo;", which I think is
>appropriate.  The second cannot automatically make everything in it extern;
>if it did, static variables in header files would break.

Eh?  You want to run that by me again??

I don't see why it would not be possible to say that given:

 extern "C" { static int foo; int bar; }

`foo' gets internal linkage, while `bar' gets external linkage.

Do you see a problem with that?

>Hmm.  Now that we have namespaces, it would seem appropriate to subsume the
>functionality of extern "C" { } into some sort of special namespace and
>deprecate the old form.

It might seem so, but it wouldn't be.  That would be just another hack
mis-overloading of a keyword (i.e. namespace) _and_ a mis-overloading of
the whole _concept_ of namespaces too.

Let namespace be namespaces.  This is a *linkage* issue!

--

-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- domain addr: rfg@netcom.com ----------- Purveyors of Compiler Test ----
---- uucp addr: ...!uunet!netcom!rfg ------- Suites and Bullet-Proof Shoes -