Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

C++ Compiler Trap, Indeterminism in function argument evaluation

Total Hit ( 5950)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
int i=0;
printf("%d %d %d %d", i++, i==1, i, ++i);

Its giving this output:
On Sun Solaris 8:
0 1 2 2
On Linux:
1 1 1 1
On Windows:
0 1 1 2


Some thoughts:

Incr/decr ops have side effect so arg list values are undefined in this case. It's an excellent example of a classic trap with evaluation order. You may have different results not only on Unix/Windows but also on different implementation on the same system.
Be careful with side effect operations.

C language/compiler tells that there is no finite rule for this type of evaluation

Multiple side effects on the SAME variable between sequence points are ALWAYS UNDEFINED within the C language.

http://c-faq.com/expr/evalorder1.html


Submitted By : Ritesh Tijoriwala  (Member Since : 6/13/2004 1:49:49 AM)

Job Description : job - Eat Computers, Drink Computers , Sleep Computers... hobby - read, Cricket, tennis...
View all (2) submissions by this author  (Birth Date : 10/10/1980 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.