小编Pov*_*asG的帖子

C在头文件中转发struct

我试图struct在函数中传递指针.我有一个typedef在file1.h,并希望只将该头包含到file2.c,因为file2.h只需要指针.在C++中我会像我在这里写的一样,但是使用C99它不起作用.如果有人有任何建议如何传递struct没有完整定义的指针,将非常感激.编译器 - gcc.

file1.h

typedef struct
{
    ...
} NEW_STRUCT;
Run Code Online (Sandbox Code Playgroud)

file2.h

struct NEW_STRUCT;

void foo(NEW_STRUCT *new_struct); //error: unknown type name 'NEW_STRUCT'
Run Code Online (Sandbox Code Playgroud)

file2.c中

#include "file2.h"

#include "file1.h"

void foo(NEW_STRUCT *new_struct)
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

c struct forward-declaration

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

forward-declaration ×1

struct ×1