home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16795 < prev    next >
Encoding:
Text File  |  1992-11-23  |  1.9 KB  |  47 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: inline functions with static local variables (was: Re: Wisdom on f(...,const class& xxx = default_xxx))
  5. Message-ID: <1992Nov23.213009.4750@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <mg.721758488@tyrolia> <1992Nov16.174152.16576@taumet.com> <9232812.10747@mulga.cs.mu.OZ.AU>
  8. Date: Mon, 23 Nov 1992 21:30:09 GMT
  9. Lines: 36
  10.  
  11. fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  12.  
  13. >steve@taumet.com (Steve Clamage) writes:
  14.  
  15. >>(because an inline function can't have static local variables).
  16.  
  17. >Why not?
  18. >Is there any restriction on this in the ARM? I couldn't see anything
  19. >in C++PL 2nd Ed.
  20.  
  21. >g++ will quite happily go ahead and inline such functions.
  22.  
  23. There is no explicit restriction, but there are also no defined
  24. semantics for them.  I should have said "should not", rather than
  25. "can't".
  26.  
  27. There is exactly one instance of any non-inline function, and exactly
  28. one instance of a static variable in any such function.  Any invocation
  29. of that function, from whatever source, refers to the same variable.
  30.  
  31. If you have static (non-global) functions called "foo" in each module
  32. in a program, and each "foo" has a static variable "i", each "i"
  33. refers to a different variable.  Calling the "foo" in module A does not
  34. set or use the "i" in module B.
  35.  
  36. You cannot in general control or predict how many copies of an inline
  37. function will occur in a program.  An inline function generally has
  38. the semantics of a static function.  Is there then one copy of the
  39. static variable per copy of the function?  The ARM does not say.
  40. Some compilers disallow static variables in inline functions because
  41. the semantics are undefined.  It might be treated as an error, or
  42. by refusing to inline the function.
  43. -- 
  44.  
  45. Steve Clamage, TauMetric Corp, steve@taumet.com
  46. Vice Chair, ANSI C++ Committee, X3J16
  47.