我有以下代碼塊編譯錯誤枚舉參數 - 爲什麼?
global_definitions.h:(這是由以下兩個標頭和源文件包括):
typedef enum { FALSE = 0, TRUE = !FALSE } bool;
頁眉文件Log.h:
void Log_Leave_Func_Int
(
Log_Module_ID_t Module_ID,
const char *Function_Name,
const bool Has_Return_Value,
const int Return_Value
);
源文件Log.c:
void Log_Leave_Func_Int
(
Log_Module_ID_t Module_ID,
const char *Function_Name,
const bool Has_Return_Value,
const int Return_Value
)
{
bool HRetVal = Has_Return_Value;
/* some code here */
}
現在,當編譯我的公關(使用CVI 2012)我收到錯誤"Log.h"(366,20) syntax error; found 'identifier' expecting ')'.
引用Log.h中的行const bool Has_Return_Value,
,這對我來說是完全神祕的。
我已經試圖改變布爾的定義
typedef enum { FALSE, TRUE } bool;
甚至
#define FALSE 0
#define TRUE 1
#define bool int
這沒什麼區別。所以,它不能與bool的定義(錯誤指出)相關。另外,局部變量HRetVal
(其類型爲bool)不會被標記爲錯誤。
我也嘗試沒有聲明參數爲const
,它顯示另一個錯誤消息("Log.h"(366,3) Missing parameter type.
),但仍然不能編譯。
將參數Has_Return_Value
的類型更改爲int
愉快地編譯(沒有意外)。另一方面,使用普通的int
並不是這裏所指的。
我不允許使用typedef枚舉的參數嗎?如果是這樣,那麼爲什麼(我在其他地方使用typedef'd枚舉沒有任何問題)?有人可以給我一個解釋,說明這裏可能是錯的嗎?
@Rhymoid我包含了我自己的文件global_definitions.h,它定義了bool(上面的),所以我認爲這不是必須的。但我可以嘗試包含'stdbool'。請給我第二個這樣做。 – Thoran
@alk更正了這個錯字,謝謝。 – Thoran
@Rhymoid ...現在我嘗試使用'stdbool',我記得,爲什麼我包含自己的定義:在這個環境中沒有'stdbool'可用。 – Thoran