What's the purpose of the casts to signed int in glibc memmove?

Viewed 189

Source code

There they do

unsigned long int dstp = (long int) dest;
unsigned long int srcp = (long int) src;

/* This test makes the forward copying code be used whenever possible.
   Reduces the working set.  */
if (dstp - srcp >= len)       /* *Unsigned* compare!  */
  {
    /* Copy from the beginning to the end.  */

I understand why they go through the trouble of casting to longs in the first place: it is to avoid Undefined Behavior by comparing pointers to (probably) different objects. And they obviously have to use unsigned longs to do the actual comparison.

But why do they cast to long int first, then implicitly to unsigned long int?

2 Answers
Related