home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: inline functions with static local variables (was: Re: Wisdom on f(...,const class& xxx = default_xxx))
- Message-ID: <1992Nov23.213009.4750@taumet.com>
- Organization: TauMetric Corporation
- References: <mg.721758488@tyrolia> <1992Nov16.174152.16576@taumet.com> <9232812.10747@mulga.cs.mu.OZ.AU>
- Date: Mon, 23 Nov 1992 21:30:09 GMT
- Lines: 36
-
- fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
-
- >steve@taumet.com (Steve Clamage) writes:
-
- >>(because an inline function can't have static local variables).
-
- >Why not?
- >Is there any restriction on this in the ARM? I couldn't see anything
- >in C++PL 2nd Ed.
-
- >g++ will quite happily go ahead and inline such functions.
-
- There is no explicit restriction, but there are also no defined
- semantics for them. I should have said "should not", rather than
- "can't".
-
- There is exactly one instance of any non-inline function, and exactly
- one instance of a static variable in any such function. Any invocation
- of that function, from whatever source, refers to the same variable.
-
- If you have static (non-global) functions called "foo" in each module
- in a program, and each "foo" has a static variable "i", each "i"
- refers to a different variable. Calling the "foo" in module A does not
- set or use the "i" in module B.
-
- You cannot in general control or predict how many copies of an inline
- function will occur in a program. An inline function generally has
- the semantics of a static function. Is there then one copy of the
- static variable per copy of the function? The ARM does not say.
- Some compilers disallow static variables in inline functions because
- the semantics are undefined. It might be treated as an error, or
- by refusing to inline the function.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-