[comp.lang.c++] static variables in inline functions

petergo@microsoft.UUCP (Peter GOLDE) (10/27/90)

Consider the following C++ program with 2 files and 1 include file:

A.H:
   #include <stdio.h>
   inline void foo()
   {
      static int i;
      ++i;
      printf("%d\n", i);
   }
X.C:
   #include "a.h"
   extern void bar();
   main()
   {
      foo();
      bar();
   }
Y.C:
   #include "a.h"
   void bar()
   {
      foo();
   }

What is the correct output from this program: Is "1" printed twice,
or is "1" then "2" printed.  I believe "1" should be printed twice,
since inline functions have internal linkage, so the i in X.C's 
version of foo() is different from the i in Y.C's version of foo().
However, this is almost certainly not what is desired, and 
the commentary in E+S states that inline is "purely an optimization"
Furthermore, the only implementation I have which compiles this program
(Turbo C++) prints "1" then "2".

Could someone enlighten me as to the correct behavior, prefereably
with references to E+S?

---
Peter Golde:       petergo%microsoft@uunet.uu.net  
"Motion gives the illusion of progress."