Re: increasing var twice in a statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux