🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #1609

Re: Linkage revisited

#1609
From: Fergus Henderson
Date: Tue, 01 Aug 1995 12:35
67 lines
3379 bytes
huber@kazoo.cs.uiuc.edu (Jay Huber) writes:

>fjh@munta.cs.mu.OZ.AU (Fergus Henderson) wrote:
>
>>This is a serious incompatibility with C, since it makes it impossible
>>to pass the address of a static function to qsort().
>
>But giving a function extern "C" linkage does not give the function
>external linkage.  For example,
>
>extern "C" void f();
>
>static void f() { cout << "ok" << endl; }
>
>Here, f has extern "C" linkage, but is not external.  It cannot
>be referneced from another module.  Take out the 'static' and it can.
>
>The above example works with CodeWarrior 6, but I'm unable to tell
>by reading the ARM if the example is correct.

That's very creative, but your example is definitely not allowed
according to the draft standard.   (For what it's worth, your
example is also rejected by Cfront 2.0.)

Here's the relevant sections from the April working paper.
I've used uppercase to highlight the pertinent sentences.

|   7.5  Linkage specifications                                 [dcl.link]
| 
| 5 Linkage can be specified for objects.  [Example:
|           extern "C" {
|               // ...
|               _iobuf _iob[_NFILE];
|               // ...
|               int _flsbuf(unsigned,_iobuf*);
|               // ...
|           }
|    --end example] Functions and objects can be declared static or inline
|   within  the  {}  of a linkage specification.  The linkage directive is
|   ignored for a function or object with internal linkage (_basic.link_).
|   A  FUNCTION  FIRST  DECLARED  IN  A LINKAGE SPECIFICATION BEHAVES AS A
|   FUNCTION WITH EXTERNAL LINKAGE.  [EXAMPLE:
|           extern "C" double f();
|           static double f();     // ERROR
|   IS ILL-FORMED (_dcl.stc_).  ] 

The cross-reference to `dcl.stc' refers to the following text:

|   7.1.1  Storage class specifiers                              [dcl.stc]
| 
| 7 THE  LINKAGES  IMPLIED  BY  SUCCESSIVE DECLARATIONS FOR A GIVEN ENTITY
|   SHALL AGREE.  That is, within a given scope, each declaration  declar­
|   ing  the  same  object name or the same overloading of a function name
|   shall imply the same linkage.  Each function in a given set  of  over­
|   loaded functions can have a different linkage, however.  [Example:
|           static char* f(); // f() has internal linkage
|           char* f()         // f() still has internal linkage
|               { /* ... */ }
|           char* g();        // g() has external linkage
|           static char* g()  // ERROR: INCONSISTENT LINKAGE
|               { /* ... */ }

-- 
Fergus Henderson              | Designing grand concepts is fun;
fjh@cs.mu.oz.au               | finding nitty little bugs is just work.
http://www.cs.mu.oz.au/~fjh   | -- Brooks, in "The Mythical Man-Month".
PGP key fingerprint: 00 D7 A2 27 65 09 B6 AC  8B 3E 0F 01 E7 5D C4 3F
Technical Details
Message-ID: <9521322.13146@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjh
References: <3uej90$8t7@engnews2.Eng.Sun.COM> <bill_law-1807951030140001@bill-law.taligent.com> <9520602.10364@mulga.cs.mu.OZ.AU> <3vb21g$e7a@vixen.cso.uiuc.edu>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c++
Path: arc1-ca.pugleaf.net!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: Linkage revisited
Message-ID: <9521322.13146@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <3uej90$8t7@engnews2.Eng.Sun.COM> <bill_law-1807951030140001@bill-law.taligent.com> <9520602.10364@mulga.cs.mu.OZ.AU> <3vb21g$e7a@vixen.cso.uiuc.edu>
Date: Tue, 1 Aug 1995 12:35:16 GMT