comp.lang.c
[Top] [All Lists]

Re: Implementation-defined behaviour

Subject: Re: Implementation-defined behaviour
From: "Stephen Sprunk"
Date: Sat, 29 Mar 2008 18:02:23 -0500
Newsgroups: comp.lang.c


"Ioannis Vranos" <ivranos@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:fsinrj$140r$1@xxxxxxxxxxxxxxxxxxxxxx
K&R2 mentions the following:

"printf("%d %d\n", ++n, power(2,n));   /* WRONG */

can produce different results with different compilers, depending on
whether n is incremented before power is called".

It can even produce different results with the same compiler, depending on the phase of the moon (or, more likely, various optimization settings). Since there is no sequence point between evaluating arguments to a function call, the behavior is undefined.

That's why I call it implementation-defined behaviour.

No. "Implementation-defined behavior" means that an implementation is required to pick one particular behavior and document that's what it does. That is not the case here.

S

--
Stephen Sprunk         "God does not play dice."  --Albert Einstein
CCIE #3723         "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy