Re: printf output



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.

I was surprised when I was the print out.

What print out did you expect?


--
Ioan - Ciprian Tandau
tandau _at_ freeshell _dot_ org

.



Relevant Pages

  • Re: Cohens paper on byte order
    ... the external data model to a bit stream, ... comparable standards do specify external data ... sequence, and which therefore does not provide guidance ... standard character codes). ...
    (sci.crypt)
  • 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: Rand() with base
    ... >> same sequence of PRNs? ... But it doesn't specify which seed has to generate ... No, the Standard does not ... to specifying the 'rand' algorithm, which the Standard doesn't do (and we ...
    (comp.lang.c)
  • Re: x=(x=5,11)
    ... also has undefined behavior, for the same reason. ... Its obvious that there doesn't have to be _any_ sequence point ... The evaluation of the left and right operands of a binary operator can ... And I think this is probably what the standard ...
    (comp.lang.c)