- 论坛徽章:
- 0
|
下面这个代码是在wget的源码中看到的,
1、定义了两个指针p, cp 指向buffer[]数组,一个是static char 一个是 char,这样的好处是啥子?
2、感觉定义的static char *p = buffer;在这里定义有点多余,感觉用不上;
3、if语句中,为啥写成了p + size >= buffer + sizeof (buffer), 直接用 size >= sizeof(buffer) 不是一样的么?
4、后面来了句 p += size;这个是搞啥子的啊?
发现完全不知道这个函数里面这么的意思了,请求解惑,谢谢。- /* Return a string that contains S with "no-" prepended. The string
- is NUL-terminated and allocated off static storage at Wget
- startup. */
- static char *
- no_prefix (const char *s)
- {
- static char buffer[1024];
- static char *p = buffer;
- char *cp = p;
- int size = 3 + strlen (s) + 1; /* "no-STRING\0" */
- if (p + size >= buffer + sizeof (buffer))
- abort ();
- cp[0] = 'n', cp[1] = 'o', cp[2] = '-';
- strcpy (cp + 3, s);
- p += size;
- return cp;
- }
复制代码 |
|