Re: printf output
Nelu said:
On 2009-02-17, Keep Asking <ask8y@xxxxxxxxx> wrote:
What is output of following printf should be?
i=0;
printf("i=%d i++=%d i++=%d", i, i++, i++)?
Undefined behavior as i is modified multiple times between
sequence points. The C standard doesn't specify a well defined
behavior for this.
You can't have any expectations.
Yes, he can. Clearly, he does. Or did.
I was surprised when I was the print out.
What print out did you expect?
A better response.
--
Richard Heathfield <
http://www.cpax.org.uk>
Email: -
http://www. +rjh@
Google users: <
http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.
Relevant Pages
- Re: Sub-sub-expression evaluation order
... > anything in the standard that says that it must complete (ignoring side- ... The evaluation can be implemented in any way, ... There are indeed sequence points at the beginning of each function's ... requirements of the standard and the code produces undefined behavior. ... (comp.lang.c) - Re: Further along the evaluation order: Was: Order of evaluation.
... is an example from the C Standard of undefined behavior. ... There is a sequence point at the semicolon. ... Standard declares that modifying an object twice between sequence ... (alt.comp.lang.learn.c-cpp) - Re: second fclose() should not segfault
... quoted the section of the standard that says it's undefined behavior ... At the time you wrote that, the relevant sections of the standard ... calling fclose() twice with the same FILE* argument invokes undefined ... it does specify that the value of the pointer that used to point to ... (comp.std.c) - Re: size_t overflow
... The ISO standard seems to permit segmented memory models in that way. ... Since it's not strictly conforming, implementations are free to reject it; but is there a general rule that makes its behaviour completely undefined even on implementations that accept it? ... Something that wouldn't exclude implementation defined and unspecified behavior, as far as they're not relied on in a way that would make the program expose undefined behavior later on. ... With this new wording, excluding unspecified and implementation defined behavior from the list of things that a "portable" program mustn't do, the concept of "portable" program would *still* be bogous because of implementation limits. ... (comp.std.c) - Re: Buffer overflows and asctime()
... I agree with that, it doesn't require implementations ... discussion by disagreeing about what the standard says about asctime? ... There are numerous other library functions that have undefined behavior ... You seem to be ignoring proposals to leave it undefined, ... (comp.std.c) |
|