在我定義了一個.h文件中返回一個typedef:問題試圖在C
#define PAIR_TYPE(type1, type2)\
typedef struct { \ // added \ after edit
type1 first; \ // added \ after edit
type2 second; \ // added \ after edit
}; // added ; after edit
#define MAKE_PAIR(val1, val2) {val1, val2}
PAIR_TYPE(char *, uint32_t) mypair;
mypair foo();
在.c文件我用這樣的:
mypair foo()
{
mypair p;
uint32_t bar = calculate();
p = MAKE_PAIR("normal", target);
return p;
}
但是我得到這個錯誤:
error: expected expression before ‘{’ token
它指向的行是:
p = MAKE_PAIR("normal", target);
我不知道它爲什麼說'{'!!!那條線上沒有'{'。
在預處理程序完成之後有一個{提示:它將用...替換MAKE_PAIR)。我建議你看看預處理後的輸出,你的編譯器幾乎肯定有一個選項標誌只能預處理。 – Vicky
我看到....感謝您的回答 – mahmood