On Nov 7, 11:49 pm, Juha Nieminen <nos...@thanks. invalidwrote:
Salt_Peter wrote:
On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.c omwrote:
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.kan ze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
On Nov 7, 5:49 pm, Juha Nieminen <nos...@thanks. invalidwrote:
>Salt_Peter wrote:
>>On Nov 7, 4:20 am, "c/c++ programming lover" <564462...@qq.c omwrote:
>>>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"?
>
Its a syntax error, yes, thats the obvious answer. Error or not, the
OP's intent was to ask what the following might have a guaranteed
result:
>
int n(5);
printf("%d",++n *++n);
Intent or not, what he wrote produces a syntax error.
Comment