order of evaluation & static variables

Andre Dolenc ado at sauna.hut.fi
Tue Oct 30 18:59:09 AEST 1990


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 ??
(Yes, a well-known compiler returns (a) even without code opt.)
Thanx in advance,
----------------------------------------------------------------------------
Andre' Dolenc                              Helsinki University of Technology
Research Associate                         TKO, Otakaari 1A, Espoo
Email (Internet): ado at sauna.hut.fi         SF-02150  Finland
----------------------------------------------------------------------------



More information about the Comp.std.c mailing list