請參閱ISO/IEC 9899:1999標準7.1.2章節: If used, a header shall be included outside of any external declaration or definition, and it shall first be included before the firany of the function to first be included或 objects it declares, or to any of the types or macros it defines.
針對你的問題,應該把#include指令從ft_errors提出來:
#include FT_ERRORS_H
// I assume that FT_ERRORS_H has been correctly defined with corresponding header file name
static const struct ft_error ft_errors[] =
{
// concrete struct definition/declaration
};
#include
只能出現在檔案的開頭假設你的頭檔定義為 FT_ERRORS_H.h,則需要修改為
static const struct ft_error ft_errors[] =
{
};
即需要包含頭檔。在編譯器編譯的時候,會把頭檔的內容映射到陣列內。
FT_ERROR_H看起來不像是頭檔的名字,或許你指的是 "ft/error.h" ?
另外,#include這麼用預編譯是能通過的,頭檔裡的文字會被替換到這裡來。但是這樣
不利於debug,你可以說說你的需求,我們可以換一種方式來做這個事情。
include指令必須定義於檔案域(不是只能定義在檔案頭!),同時必須在第一次使用其中定義的任何函數包或變數前定義。
請參閱ISO/IEC 9899:1999標準7.1.2章節:
If used, a header shall be included outside of any external declaration or definition, and it shall first be included before the firany of the function to first be included或 objects it declares, or to any of the types or macros it defines.
針對你的問題,應該把#include指令從ft_errors提出來:
參考:
http://stackoverflow.com/questions/16389126/can-the-pre-processor-directives-like-include-be-placed-only-at-the-top-of-the
http://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf