Re: C local auto-initialized?
Re: C local auto-initialized?
- Subject: Re: C local auto-initialized?
- From: Jonas Maebe <email@hidden>
- Date: Fri, 21 Sep 2007 00:43:57 +0200
On 20 Sep 2007, at 23:02, Fritz Anderson wrote:
void partial(void)
{
#if STRANGENESS
double sumY, sumY2;
#else
double sumY2, sumY;
#endif
// [1]: sumY2 is garbage
double y = 4.0;
sumY2 += y * y; // [2]: sumY2 used uninitialized
printf("sumY2 = %f", sumY2);
#if STRANGENESS
// [3a]: sumY2 is nonetheless 16.0
#else
// [3b]: sumY2 is garbage plus 16.0
#endif
}
//==============================
Notice that sumY2 is used without being initialized. In both
configurations, it contains garbage after [1].
Which garbage? Note that floating point math is inexact, and if sumY2
contained a very small value it may simply get lost as a rounding
error after you add 16.0 to it.
Jonas
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden