🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: static in inline

#2283
From: Fergus Henderson
Date: Mon, 23 Oct 1995 17:38
37 lines
1837 bytes
krotoff@boy.nmd.msu.ru (Alexsander Krotoff) writes:

>If the the static variable is defined in the body of `inline'
>function, and compiler sucseed to substitute function body
>sevral times, shall these function copyes share common
>static variable?

Yes.

>What is about initialization of this static
>variable with non-constant?

It had better get initialized only once.

>What shall happen, if the function
>body is defined and substituted in the number of compilation
>units?

If it was a member function, or it was declared as `extern inline',
then each of the definitions must be identical (as defined by the ODR),
and there is still only one variable, which must get initialized
at most once.  Each instance of the function refers to the same static
variable.

If the function was not a member function, then linkage defaults
to static, and so if it is not explicitly specified as `extern'
then each translation unit gets its own copy of the function, each of 
which has its own static variable.  (However, multiple calls
to the same inline function from within the same translation unit
will all refer to the same copy of any local static variables.)


---
[ 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: <9529610.7210@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <462qb5$ee1@alpha.phys.msu.su>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Newsgroups: comp.std.c++
Subject: Re: static in inline
Date: 23 Oct 1995 17:38:22 GMT
Organization: Computer Science, University of Melbourne, Australia
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <9529610.7210@mulga.cs.mu.OZ.AU>
References: <462qb5$ee1@alpha.phys.msu.su>
NNTP-Posting-Host: physics2.berkeley.edu