• 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: GCC not doing the correct thing?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GCC not doing the correct thing?


  • Subject: Re: GCC not doing the correct thing?
  • From: Keith Ray <email@hidden>
  • Date: Mon, 11 Nov 2002 06:43:05 -0800

Some compilers will generate code for
x = (a++) + (a++);
that gets different results depending on the level of optimization being used. I've seen this VisualC++ 6.0, for example. If a == 0, x could be 2 or 3.

Since this expression is declared "undefined behavior" by the current ISO/ANSI C standards, any value is possible.

The only SAFE implementation (that works regardless of compiler optimization levels and compiler implementation) of
result = ((*ptr++) * (*ptr++) * (*ptr++))
is
value1 = (*ptr++);
value2 = (*ptr++);
value3 = (*ptr++);
result = value1 * value2 * value3;

On Monday, November 11, 2002, at 06:21 AM, Clark S. Cox III wrote:

I hate to break it to you, but the original K&R is irrelevant. C has changed dramatically since then, and wether or not you believe me, incrementing the same variable more than once before a sequence point is undefined, the C standard says so, and the C standard is the final word on the C language.
If you still don't believe me, please read the FAQ for, and/or post to comp.lang.c, comp.lang.c++ or alt.comp.lang.learn.c-c++, or read the C standard itself.

--
C. Keith Ray
<http://homepage.mac.com/keithray/xpminifaq.html>
<http://homepage.mac.com/keithray/resume.html>
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: GCC not doing the correct thing? (From: "Clark S. Cox III" <email@hidden>)

  • Prev by Date: Controlling default field editor contextual menu??
  • Next by Date: Re: GCC not doing the correct thing?
  • Previous by thread: Re: GCC not doing the correct thing?
  • Next by thread: Re: GCC not doing the correct thing?
  • Index(es):
    • Date
    • Thread