use of if (!cptr) and if (cptr), where cptr is a *
Raphael Mankin
raph at tigger.planet.bt.co.uk
Fri Jul 28 18:08:38 AEST 1989
ari at eleazar.dartmouth.edu (Ari Halberstadt) writes:
>In article <2990 at nmtsun.nmt.edu> dwho at nmtsun.nmt.edu (David Olix) writes:
>#>[Skipping all the "In article..." stuff]
>#>>[Material everybody has seen n times deleted.]
>True, parenthesis have the highest priority, but that is not relavent.
>Syntactically, what you have is:
> while (expr1 != expr2) { ... }
>Since the two expressions are totally separate, the compiler is free
>to do whatever it chooses. The expressions become a single expression when
>(and only when) the compiler evaluates the != operator. The whole reason
>for not defining order of evaluation was to allow machines to evaluate things
>in the fastest way.
>Grouping is not the same as order of evaluation...it's been a while since
>I've gone over that, and I don't have a book in front of me right now.
>The ANSI C standard has formalized all these things, but again, I don't
>have a copy in front of me.
The order of evaluation of operands and the order of application of operators
have little to do with each other. The compiler could evaluate _all_ the
operands before applying _any_ operators (except && ||). This applies also
to the order of evaluation of subscripts and function arguments. If there
are side effects you are in dangerous waters - so don't do it.
A typical, and particularly blatant, case is
a[i] = b[i++];
or
a[i++] = b[i];
Some compilers will diagnose this. although the compiler has to
compute the RHS before it uses the LHS, there is nothing to stop it
evaluating the LHS so as to obtain the destination address before
evaluating the RHS.
More information about the Comp.lang.c
mailing list