小编Joh*_*ith的帖子

在glibc memmove中签名int的转换的目的是什么?

源代码

他们在那里

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.  */
Run Code Online (Sandbox Code Playgroud)

我理解为什么他们首先要经历长期投射的麻烦:通过比较(可能)不同对象的指针来避免未定义的行为.他们显然必须使用无符号长度来进行实际比较.

但他们为什么long int要先投入,然后隐含地投入unsigned long int

c language-lawyer

9
推荐指数
1
解决办法
156
查看次数

标签 统计

c ×1

language-lawyer ×1