• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C local auto-initialized?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >C local auto-initialized? (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Re: C local auto-initialized? [SOLUTION AND APOLOGY]
  • Next by Date: deploying software requiring libgcc
  • Previous by thread: Re: C local auto-initialized?
  • Next by thread: Re: C local auto-initialized?
  • Index(es):
    • Date
    • Thread