[comp.os.msdos.programmer] Correction to far_ptr_cmp

naga@wet.UUCP (Peter Davidson) (04/26/91)

days ago, for comparing far pointers, requires a correction.
I forgot to add the (unsigned long) casts in the first two lines.
Shoot!  We'll at least I noticed before anyone else did
(or at least before anyone else posted a correction
(or at least before anyone did and it arrived here)).

The function returns -1 if the physical memory address of ptr1 is
less than that of ptr2, 1 if greater than and 0 if they point to
the same memory location.

int far_ptr_comp(void far *ptr1,void far *ptr2)
{
unsigned long p1 = ( ( (unsigned long)FP_SEG(ptr1)<<4 ) + FP_OFF(ptr1) );
unsigned long p2 = ( ( (unsigned long)FP_SEG(ptr2)<<4 ) + FP_OFF(ptr2) );
int result=0;

if ( p1 < p2 )
    result--;
else if ( p1 > p2 )
    result++;

return ( result );
}