取消引用指向不完整类型"const struct cred"的指针 [英] Dereferencing pointer to incomplete type ‘const struct cred’

查看:176
本文介绍了取消引用指向不完整类型"const struct cred"的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解这个错误.打印进程的UID,代码:

I want to understand this error. Printing UID of a process, code:

printk(KERN_INFO "User ID = %d\n", (task)->cred->uid);

错误:

error: dereferencing pointer to incomplete type ‘const struct cred’

推荐答案

这很简单:编译器告诉您struct cred类型不完整.换句话说,编译器不知道其定义,因此不知道是否存在uid字段或该字段在struct中的位置.因此,它无法编译该->uid.

It's pretty straightforward: the compiler is telling you that the type struct cred is incomplete. In other words, the compiler does not know its definition, and therefore it does not know whether there is a uid field or where in the struct the field is located. Therefore it cannot compile that ->uid.

要解决此问题,只需添加正确的struct cred定义:

To fix this, simply include a correct definition of struct cred:

#include <linux/cred.h>

这篇关于取消引用指向不完整类型"const struct cred"的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆