This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: increasing var twice in a statement
- From: "chris at blueband dot demon dot co dot uk" <chris at blueband dot demon dot co dot uk>
- To: willi at wm1 dot at, gcc-help at gcc dot gnu dot org
- Date: Fri, 15 Jun 2007 10:37:16 -0400
- Subject: RE: increasing var twice in a statement
- Reply-to: chris at blueband dot demon dot co dot uk
I feel 10 is the correct answer due to the pre-increment operator having a
higher precedence than the addition operator. This would mean both
increments will be done before the addition (creating 5 + 5).
Chris
Original Message:
-----------------
From: Willi Mann willi@wm1.at
Date: Fri, 15 Jun 2007 16:28:32 +0200
To: gcc-help@gcc.gnu.org
Subject: increasing var twice in a statement
Hi!
Can anybody tell me what output the following program snippet should
produce according to C standard:
int main(void) {
int a;
int b;
b = 3;
a = ++b + ++b;
printf("%d\n",a);
return 0;
}
I would have expected 9, but gcc 4.1.2 produced a binary that wrote 10.
Willi
Please CC: me in replys, I'm not on the list.
--------------------------------------------------------------------
mail2web.com ? What can On Demand Business Solutions do for you?
http://link.mail2web.com/Business/SharePoint