What is the difference

utzoo!decvax!harpo!floyd!vax135!ariel!and utzoo!decvax!harpo!floyd!vax135!ariel!and
Fri May 13 09:57:16 AEST 1983


In c-language, logical expressions are evaluated only enough
to determine truth or falsity of the entire expression,
so the p++ in (2) may not be reached - regardless of the
ORDER of evaluation.

There are, at least, two solutions.

1) One is Coltoff's 1).  Why must the ++ be inside?

2) Shift the endpoints of the range of p so as to use ++p
in the first place it is used.  Thus it is always evaluated.
This may be tricky, and in the sense that one needs to be
certain of the order, may be harder.
For example, suppose the if-expression is a tautology and
always TRUE, and suppose the c-compiler were smart enough
to recognize that fact.  Then no part of the expression
would have to be evaluated.

Richard



More information about the Comp.lang.c mailing list