我有以下代码:
文件调度.h
#ifndef __SCHED_H__
#define __SCHED_H__
#include <stats.h>
truct task_struct {
...
struct stats stat;
};
#endif
文件状态h
#ifndef STATS_H
#define STATS_H
#include <sched.h>
struct stats
{
...
};
void initStats (struct task_struct* tsk);
#endif
当我试图编译时,它会给我以下警告
警告:“struct task_struct”声明的内部参数列表将在此定义或声明之外不可见,此定义或声明为17 inside (struct task_struct* tsk);
我也看到过类似的问题,但我没能解决这个问题。我想知道问题是否是因为这两个文件都包含了对方。如有任何帮助,将不胜感激:)。
编辑:我在代码中改变了一些东西。现在,我不是使用task_struct作为参数,而是使用struct。但是,现在调度.h文件无法找到struct的声明。我不知道怎么解决这个问题。由于编译器给我的错误不同,我发布了一个新的问题:Problem with declaration of structs in header files: "error: field 'stat' has incimplete type"
发布于 2021-04-03 09:01:59
在声明函数时,文件范围中的结构struct task_struct
的先前声明似乎是不可见的。
如果是,那么在这个函数声明中
void initStats (struct task_struct* tsk);
类型说明符struct task_struct
具有函数原型范围,在函数原型之外不可见。
也就是说,此类型说明符与类型说明符不相同。
struct task_struct {
...
struct stats stat;
};
在函数原型之外声明。
来自C标准(6.2.1标识符Scopes )
和
的末尾。
下面是一个再现编译器消息的演示程序。
#include <stdio.h>
// struct A;
void f( struct A );
struct A
{
int x;
};
int main(void)
{
return 0;
}
prog.c:5:16: error: ‘struct A’ declared inside parameter list will not be visible outside of this definition or declaration [-Werror]
void f( struct A );
^
如果要取消对前向声明的注释
// struct A;
那么错误信息就会消失。
https://stackoverflow.com/questions/66929337
复制相似问题