我想通過函數中的struct
指針。我在file1.h中有一個typedef
,並且只想將這個頭文件包含到file2.c中,因爲file2.h只需要指針。在C++中,我會像我這樣寫,但使用C99它不起作用。如果有人有任何建議如何通過struct
沒有完整定義的指針,將不勝感激。編譯器 - gcc。C正向聲明頭結構中的結構
file1.h
typedef struct
{
...
} NEW_STRUCT;
file2.h
struct NEW_STRUCT;
void foo(NEW_STRUCT *new_struct); //error: unknown type name 'NEW_STRUCT'
file2.c中
#include "file2.h"
#include "file1.h"
void foo(NEW_STRUCT *new_struct)
{
...
}
* 「這是行不通的。」 *解釋說。你有沒有編譯錯誤?一個鏈接器錯誤?運行時崩潰?發生了什麼? – abelenky
對不起,忘了。它既不像這樣編譯,也不是如果我將'struct'添加到函數參數中,那麼錯誤將更改爲「函數foo'參數類型不匹配」。 – PovilasG