【发布时间】:2017-03-21 05:28:42
【问题描述】:
我有两个文件,file.h 和 file.c
在头文件中我有以下定义:
struct openfile {
struct vnode *of_vnode;
struct lock *of_lock;
off_t of_offset;
int of_accmode; /* from open: O_RDONLY, O_WRONLY, or O_RDWR */
int of_refcount;
};
和
struct filetable {
struct openfile *ft_openfiles[MAX_FILES];
};
我正在尝试访问 file.c 中的 openfiles 数组。例如,
int fd;
/* NULL-out the table */
for (fd = 0; fd < MAX_FILES; fd++) {
curthread->t_filetable->ft_openfiles[fd] = NULL;
}
访问 ft_openfiles 数组的行在编译期间导致错误。
../../userprog/file.c:157: error: dereferencing pointer to incomplete type
我在这里查看了一些相关问题,但我并不真正理解错误。
【问题讨论】:
-
This post 是相关的。
-
什么是
curthread,什么是t_filetable?这些都是必要的 -
还可以尝试用
curthread->t_filetable->ft_openfiles[fd] = {NULL};替换有问题的行,看看是否可行。如果是的话,我会把它放在一个答案中。 -
这些文件用于管理内核线程结构内打开的文件。初始化函数可以在多个线程中调用。需要 curthread 和 t_filetable 来确保我只访问当前线程的文件系统。我将 NULL 替换为 {NULL},我收到以下错误:“{”标记之前的预期表达式
标签: c compiler-errors