|
From: | Jeffrey Holle |
Subject: | Re: Odd g++ results |
Date: | Sat, 27 Sep 2003 18:26:58 -0700 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 |
If one codes like: int main() { int a = count(); int b = count(); int c = count(); cout << "first " << a << " second " << b << " third " << c << " \n"; } The output is as you expected. Randy Goldenberg wrote:
Hi.From the very simple code below, I expected the output tobe: first 1 second 2 third 3 Compiling with g++ on Solaris, that was what I got. However, the same code compiled on Linux outputted: first 3 second 2 third 1 Ideas? #include <iostream> using namespace std; int count(){ static int j = 0;j++;return j; }int main(){cout << "first " << count() << " second " << count() << " third " << count() << " \n"; }
[Prev in Thread] | Current Thread | [Next in Thread] |