Article View: comp.std.c
Article #1902Re: order of evaluation & static variables
From: Stephen Clamage
Date: Tue, 30 Oct 1990 16:17
Date: Tue, 30 Oct 1990 16:17
24 lines
1221 bytes
1221 bytes
ado@sauna.hut.fi (Andre Dolenc) writes:
|Consider the following code fragment:
|-----------
|float *ff (p) float p;
|{
| static float gv;
| gv = p; return &gv;
|}
|main ...
|{ printf ("= %f\n", *(ff((float)1.0)) + *(ff((float)2.0))); ... }
|-----------
|Everyone *expects* the answer to be 3.0 (approx; change 'float' to
|'int' if you do not like rounding errors in the example...). However,
|can a conforming implementation return (a) 1+1=2, or (b) 2+2=4 ??
Well, I must not be everyone. I certainly don't expect the answer to
be 3.0. A conforming implementation must evaluate both calls to ff()
before calling printf() -- that is all that is assured. The ANSI
standard explicity says that the order in which side effects occur
between sequence points is unspecified.
--
Steve Clamage, TauMetric Corp, steve@taumet.com
Technical Details
Message-ID:
<495@taumet.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steveReferences:
<1990Oct30.075909.3848@santra.uucp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.std.c Subject: Re: order of evaluation & static variables Message-ID: <495@taumet.com> Date: 30 Oct 90 16:17:06 GMT References: <1990Oct30.075909.3848@santra.uucp> Organization: Taumetric Corporation, San Diego Lines: 24