Bug 50425 - precedence rule for pre/post increamet/decreament and effect of white spaces
Summary: precedence rule for pre/post increamet/decreament and effect of white spaces
Status: VERIFIED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-15 18:16 UTC by Ganga Jaiswal
Modified: 2011-09-16 06:25 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ganga Jaiswal 2011-09-15 18:16:01 UTC
Hi,
I was trying to understand precedence of pre/post increment/decrement operators.
But it seems to be very confusing. According to precedence rule pre increment has higher precedence than addition(+) and lower precedence than post lineament.
 But when I use any expression like j= i + ++i + i + ++i; according to precedence rule pre icrements will be performed first and then remaining statement. suppose value of i=2, according to precedence rule pre increments will be performed first and then addition. So after two pre increments value of i becomes four and this value should be used in evaluation of complete statement and it should be 16 but it is not. What is correct rule of precedence in this case ??
Similarly in C, generally white spaces does not make any sense but in following case they are they are behaving differently.consider following statements:
j = i +++ i;
j= i++ + i;
j=i + ++i;
j=i + + + i;
Please let me know, how are white space treated in this case? please follow a consistent rule. Also clarify precedence rule of these operators.
Comment 1 Andrew Pinski 2011-09-15 18:21:31 UTC
This is not a good place to learn C/C++ really.  But anyways the order of evulating of the operands of + is not specified and could happen in either order as there is no sequence point.  Read http://c-faq.com/expr/seqpoints.html .
Comment 2 Ganga Jaiswal 2011-09-16 06:25:27 UTC
Thanks Andy.