🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

??? static locals in inline functions ???

#2407
From: Kaelin Colclasure
Date: Fri, 03 Nov 1995 03:29
52 lines
2004 bytes
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:

	inline int *
	foo()
	{
	    static int i;
	    return &i;
	}

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

	#include "foo.h"
	...
	*foo() = 1;
	...

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

	#include <iostream.h>
	#include "foo.h"
	...
	cerr << "*foo() = " << *foo() << endl;
	...

Some data points:

MSVC++:	*foo() = 1
G++:	*foo() = 0
Sun C++:*foo() = 0
CFront:	"sorry, not implemented"

My intuition is that MSVC++ is doing the "right" thing (gasp), and what
"should" be the standard thing-- but I realize that the behavior I
want requires mangling a global variable name or the moral
equivalent.  I want to know if the standard requires this or leaves
the behavior implementation defined...

-- 
// 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.95Nov2201050@binki.bridge.com>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 03 Nov 95 03:29:32 GMT
Approved: fjh@cs.mu.oz.au
From: kaelin@bridge.com (Kaelin Colclasure)
Newsgroups: comp.std.c++
Subject: ??? static locals in inline functions ???
X-Original-Date: 03 Nov 1995 02:10:50 GMT
Organization: Bridge Information Systems, Inc.
Message-ID: <KAELIN.95Nov2201050@binki.bridge.com>
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMJmNfuEDnX0m9pzZAQHMGQGAgEW2r/uKlVe9aK0BxVkQg86XDDd2s26W
 BUYttuCWYRVKwF0tgpQ3cG4T1Y8Gw3Yp
 =pZse