Bug 17095 - ++ opertator and + operator is not working together.
Summary: ++ opertator and + operator is not working together.
Status: RESOLVED DUPLICATE of bug 11751
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.3.2
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-19 07:00 UTC by Asokumar Shanmugam
Modified: 2005-07-23 22:49 UTC (History)
1 user (show)

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 Asokumar Shanmugam 2004-08-19 07:00:31 UTC
main()
{
	int x=20,y=35;
	printf("1:%d%d\n",x,y);
	x=y++ + x++; //This operation is not working
	printf("2:%d%d\n",x,y);
	y= ++y + ++x;
	printf("3:%d%d\n",x,y);
}
	
If you compile the following program it gives  following output.

gcc(3.3.2) - Wrong output
------------
1:2035
2:2136
3:2259

Ideal output should be
----------------------
1:2035
2:5636
3:5794
Comment 1 Volker Reichelt 2004-08-19 08:01:07 UTC
This is not a bug in the compiler, but in your code.
Your code triggers undefined behavior because there's no sequence
point in "x=y++ + x++". An even shorter example would be "x=x++".

*** This bug has been marked as a duplicate of 11751 ***