So, to tie
this in with the Zen Koan threads, what is the result of
int i = 0;
printf("%d %d %d\n",i++,i++,i++);
IIRC it should output:
2 1 0
Not on my system:
0 1 2
I checked after I sent the message and my system output "2 1 0"... I am
using Watcom C 10.6 under QNX 4.25.
This is three modifications to the same Lvalue within the same sequence
interval - it is therefore possible for the increment operations to be
performed in any order, and even deferred to just before the next sequence
point, so results could be:
2 1 0
0 1 2 (or any other ordering of these numbers)
0 0 0
The only thing you can be *reasonably certain of* (see below) is that at least
one of the "results" must be < 1, at least two of the results must be < 2,
and
all three results must be < 3 (since each operation must return the value prior
to the increment, and only one increment is associated with each operation).
So, although unlikely that the compiler would defer two operations and not
another, it is potentially possible that the "results" could also be 0 0 1,
0 0 2, 0 1 1 etc. (in any order).
Officially this type of code (that which modifies an Lvalue multiple times
within the same sequence interval) invokes "undefined behaviour", which
means that the compiler can do "anything" - although highly unlikely, the
compiler can happily return 6 6 6 in this case, and leave the value of i at
31415 (or anything else) ... and be performing in a perfectly legal sense
- undefined operation is exactly that. The function performed is not defined
by the standard.
On other words, it's not valid 'C' (although it is syntactically correct, and
most compilers will accept it without a diagnostic).
I think the OP's point has been completely missed (that a valid program is a
inherently very definitive and detailed specification).
Regards,
Dave
(In a way this is topical for me since my compiler is 17 years old this year)
--
dave04a (at) Dave Dunfield
dunfield (dot) Firmware development services & tools:
www.dunfield.com
com Collector of vintage computing equipment:
http://www.parse.com/~ddunfield/museum/index.html