This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: increasing var twice in a statement


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]