APUE Section:4.3 &buf 的意思

来源:百度知道 编辑:UC知道 时间:2024/09/19 19:56:22
APUE 的4.3节例子中 有这么一条语句:
……
if (lstat(argv[i], &buf) < 0) {
……

……
在4.2节中描述的lstat函数原型为:int lstat(const char *restrict pathname, struct stat *restrict buf);
照我的理解,在4.3的例子中不应该是:

……
if (lstat(argv[i], buf) < 0) {
……

……
吗?
为什么是:&buf而不是buf呢?

劳烦各位给予解释一下,非常感谢!

buf肯定是这样定义的
struct stat buf;
你好好看看lstat的函数原型最后一个参数他需要的是一个buf的地址,这样才能将一个i节点的信息保存在你所指定的buf中
int lstat(const char *restrict pathname, struct stat *restrict buf);
lstat这个函数的用途就是获取足够的 pathname指向的 i 节点的信息然后存入后面参数指定的struct stat缓冲区
因此apue中就出现 &buf 这是很正确的