Pointer arithmetic and comparisons.

Peter da Silva peter at ficc.uu.net
Fri Dec 15 01:25:24 AEST 1989


> <Now a beef.  Why check for (p <= pend)?  Why not just ( p == pend) ?

In article <2241 at dataio.Data-IO.COM> bright at dataio.Data-IO.COM (Walter Bright) writes:
> (p <= pend) generates more efficient code (on PC's) than (p == pend), because
> on the former only the offset portions of the pointer need to be compared,
> while on the latter both the segment and the offset must be compared.

Implementation-dependent micro-optimisation isn't a good reason. A good
one is that !p <= pend! is a broader termination condition, and thus safer.
-- 
`-_-' Peter da Silva. +1 713 274 5180. <peter at ficc.uu.net>.
 'U`  Also <peter at ficc.lonestar.org> or <peter at sugar.lonestar.org>.
"Scientific progress is predicated on name-calling and intolerance, not to
 mention asking lots of stupid questions." -- Mark S Madsen



More information about the Comp.lang.c mailing list