🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ??? static locals in inline functions ???

#2430
From: Kaelin Colclasure
Date: Mon, 06 Nov 1995 00:10
49 lines
2572 bytes
In article <u9g2g5xbre.fsf@yorick.cygnus.com> jason@cygnus.com (Jason Merrill) writes:

    >> What behavior does the draft standard condone for the following
    >> scenario:

    >> 1) In a header file, an inline function is defined to contain a
    >> local static, like so:

    >> 2) Two seperate modules include this header file, call them A
    >> and B.  A "initializes" foo():

    >> 3) B calls foo(), dereferences the pointer returned and prints
    >> its value:

    >> Some data points:

    >> MSVC++: *foo() = 1 G++: *foo() = 0 Sun C++:*foo() = 0

    >> My intuition is that MSVC++ is doing the "right" thing (gasp),
    >> and what "should" be the standard thing.

    Jason>    G++ and Sun conform to the current working paper for
    Jason> this example.  If foo had been explicitly declared 'extern
    Jason> inline', or if it were a member function, MS would be
    Jason> correct.

Thanks for the clarification!  I wonder, though, if this isn't
something of a gratuitious inconsistancy.  For all other function
definitions, extern is the default-- you have to use the static
keyword to restrict the definition to file scope.  Now the draft is
saying that inline functions get exactly the *opposite* semantics
(ie. static is assumed, extern must be declared explicitly).

The only reason I can fathom for this is for compatibility with
existing, pre-standard C++ code-- and I'd say that's a pretty weak
basis given my intuition that this usage in existing implementations
should be pretty rare.  Am I just missing something?
-- 
// Kaelin Colclasure -------------------------------------------------------
// EMail: kaelin@bridge.com           Mail: Bridge Information Systems, Inc.
// Voice: (314)567-8463                     717 Office Parkway
//   Fax: (314)432-5391                     St. Louis, MO 63141


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <KAELIN.95Nov4090501@binki.bridge.com>
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
References: <KAELIN.95Nov2201050@binki.bridge.com> <u9g2g5xbre.fsf@yorick.cygnus.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!howland.reston.ans.net!agate!agate!Matt
From: kaelin@bridge.com (Kaelin Colclasure)
Newsgroups: comp.std.c++
Subject: Re: ??? static locals in inline functions ???
Date: 06 Nov 1995 00:10:17 GMT
Organization: Bridge Information Systems, Inc.
Approved: Matt@Austern
Message-ID: <KAELIN.95Nov4090501@binki.bridge.com>
References: <KAELIN.95Nov2201050@binki.bridge.com>
 <u9g2g5xbre.fsf@yorick.cygnus.com>
NNTP-Posting-Host: austern.hip.berkeley.edu