Re^2: Another silly question

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Apr 29 12:08:54 AEST 1989


In article <4625 at freja.diku.dk> njk at freja.diku.dk (Niels J|rgen Kruse) writes:
-No. If you have pointers
-long *p1,*p2,*p3,*p4;
-with p1 <= p2 and p3 <= p4 and want to test (p2-p1) < (p4-p3),
-you can write
-if ((char *)p2 - (char *)p1 < (char *)p4 - (char *)p3)
-which won't generate any shifting.

That might generate shifting, depending on the implementation.
What you should write is simply
	if ( p2 - p1 < p4 - p3 )



More information about the Comp.lang.c mailing list