Re: Question about the C-Reference manual

>The origin of this question is something I read in "C: A reference
>manual" by Harbison and Steele , international edition , 5th edition.
>At the bottom of page 254 there is the following code fragment:
>char *x[10] , **p=x;
>if ( strcmp(*p++, *p++) == 0 ) printf("Same");
>According to the book , if the string pointed to by p is s1 and the
>string pointed to by p+1 is s2 , then the if statement will determine
>if s1 and s2 are equal.The reason for that , as explained on the same
>page , is that in a function call one argument will be chosen and
>evaluated fully , then another and so on until the arguments are

The commas separating arguments in a function call are *NOT* comma
operators, and there is *NOT* a sequence point between evaluation
of different arguments.

>So in strcmp(*p++, *p++) one of *p++ will be chosen and
>evaluated fully ,

"evaluated fully" corresponds roughly to the idea of a sequence
point, and no, there is NOT a sequence point between evaluation of
each argument.

>then the other one.We don't know if the *p++ before
>or after the comma will be evaluated first but of course in this
>particular case it doesn't affect the final outcome.

You don't know that. The two values returned to p may be returned
*SIMULTANEOUSLY*, and gating two values into the same register at
the same time may cause an overload and cause a warp core containment breach.

It could also just as well compare the first string against the
first string, and always compare equal.

>On the other hand on the opposite page (255) we read that strcmp(*p++,
>is undefined.My impression was that undefined means anything goes ;
>for all you know it may turn your computer into a frog.But the example
>above gives the impression that even when an expression is undefined
>can still predict the behaviour up to a point.So what gives , is
>strcmp(*p++, *p++) undefined and I have the wrong idea about what
>means or is the example wrong ?

Undefined behavior includes having the "obvious" behavior until
the boss is watching, when it does something different.

Gordon L. Burditt
comp.lang.c.moderated - moderation address: clcm@xxxxxxxxxxxx -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.