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: jlh <jlh at gmx dot ch>
- To: Willi Mann <willi at wm1 dot at>, gcc-help at gcc dot gnu dot org
- Date: Fri, 15 Jun 2007 17:04:20 +0200
- Subject: Re: increasing var twice in a statement
- References: <4672A210.4070606@wm1.at>
> Can anybody tell me what output the following program snippet
> should produce according to C standard:
I think this case produces undefined behavior, so by the C
standard, 9 would be as correct as 10 or 42. Compiling your code
with "-O2 -Wall" even produces a warning:
a.c:5: warning: operation on 'b' may be undefined
The reason is that you're modifying a variable twice within the
same two sequence points. See
http://en.wikipedia.org/wiki/Sequence_point
jlh