Topic: static in inline
Author: "john (j.d.) hickin" <hickin@bnr.ca>
Date: 1995/10/19 Raw View
I won't quote from the standard because I don't have a copy.
I will, however, express my opinion on what behavior makes sense.
The inline keyword is just a compiler hint and the implementation may choose to
ignore a hint at its discretion. The case in hand is one where the compiler
must treat the case as an error (as, for example, does cfront) or where it must
bend over backwards to insure that only one version of the static variable is
produced. This latter approach is too subtle for my liking, as you get into
initialization problems as your posting has implied.
--
John Hickin Bell-Northern Research, Montreal, Quebec
(514) 765-7924 hickin@bnr.ca
---
[ 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. ]
Author: John Max Skaller <maxtal@suphys.physics.su.oz.au>
Date: 1995/10/22 Raw View
krotoff@boy.nmd.msu.ru (Alexsander Krotoff) wrote:
>Hello C++ gurus,
>
>I know, this question is asked here some time ago, but I found
>no changes in the October Working Draft and want to ask it again.
>
>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. And AFAIK the appropriate words ARE in the latest WP.
>What is about initialization of this static
>variable with non-constant? What shall happen, if the function
>body is defined and substituted in the number of compilation
>units?
Thats the implementors problem.
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
AUSTRALIA email: skaller@maxtal.com.au
---
[ 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. ]
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: 1995/10/23 Raw View
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. ]