James Kanze
11/8/2008 9:20:00 AM
On Nov 7, 11:49 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> Salt_Peter wrote:
> > On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.com> wrote:
> >> Could anyone tell me why the result is that:
> >> printf("%d",++5*++5);
> >> the result is 49?
> >> thanks
> > It doesn't matter what the result is. Its undefined
> > behavior.
> Does the standard really specify a syntax error as "undefined
> behavior"?
It does, actually. The implementation is required to emit a
diagnostic, but what happens next is undefined behavior.
In practice, of course, from a QoI point of view, the
implementation will normally not generate an object file. The
rule is there to allow the implementation to use ill-formed
constructs as an extension; once the compiler has output a
diagnostic (the message "this is an extension", for example),
it's free to go on and compile the code, assigning any meaning
it wants to it.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34