Re: C FAQ 3.1



Purnank wrote:
>
> "Stan Milam" <stmilam@xxxxxxxxxx> wrote in message
> news:37qbe.768$m85.35@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> > Peter Nilsson wrote:
> > > ccwork wrote:
> > >
> > >>Hi all,
> > >
> > >>Why can't it be unspecified?
>
> <snip>
> discusssion is about
> int i = 7;
> printf("%d\n", i++ * i++);
> prints 49. Regardless of the order of evaluation, shouldn't it print
> 56?
>
> I think this is interesting.
> What metrics can we use to determine it is
> undefined or unspecified?

It violates a "shall constraint" and is undefined.

N869
6.5 Expressions
[#2] Between the previous and next sequence point an object
shall have its stored value modified at most once by the
evaluation of an expression.

> > > The real question is: Why _should_ it be specified?

> > Because it would clear up a lot of confusion,
> > specify exactly what the behavior should be.
> > I am convinced we have undefined behavior because
> > K&R were too lazy or in a hurry to specify exactly
> > what should happen in these now undefined cases.

It would only add to your confusion.
Code which exhibits undefined behavior like that,
is so substandard, that it is actually not C code.
It's just gibberish that looks like C code.

--
pete
.



Relevant Pages

  • Re: Evaluation from Right to Left
    ... evaluation will take place from right to left. ... You are falling into the trap of undefined behavior. ... expressions is not a sequence point, ... "Between the previous and next sequence point an object shall have ...
    (comp.lang.c)
  • Re: if (pointer) ?
    ... based on expressions that return values. ... The idea that C takes ideas from Lisp at first seems ... and this is exploited for guarding against erroneous evaluation within the ... Just like the C avoiding evaluating p->property when p is null, ...
    (comp.lang.c)
  • Re: [patch 0/2] Immediate Values - jump patching update
    ... assembly ("g" constraints for all the expressions), ... That unconditional evaluation can easily entail memory reads and ... trace things, which i believe any usable kernel tracer must offer), ... runtime overhead that current markers have. ...
    (Linux-Kernel)
  • Re: [comp.lang.c.moderated] Re: Interaction between global pointers
    ... "The order of evaluation of the function designator, the arguments, ... is a sequence point before the actual call." ... C89 6.6 Statements ... The program contains undefined behavior. ...
    (comp.lang.c.moderated)
  • Re: nested backquoting (newbie) question in Clisp
    ... more expressions, ... (defmacro nth-expr (n-expr &rest exprs) ... The problem is not that insufficient evaluation is applied, ... that ELT is a function and not a control construct. ...
    (comp.lang.lisp)