2014-02-08 116 views
1

不相容我有以下代碼FILE指針:標準輸入

struct FILE *in, *out; 

if (argc == 1) { 
    /* No files were supplied so assume parsing from the stdin and printing to the stdout */ 
    in = stdin; 
    out = stdout; 
} 

然而,隨着使用gcc標誌編譯時-ansi -Wall -Wextra -Werror出現以下錯誤:assignment from incompatible pointer type

我擡頭看着GNU C Library Reference Manualstdin類型和227頁(在Adobe Reader上的251)的類型確實是FILE *,所以我不知道什麼是錯的。

+4

爲什麼'struct'? –

+0

編譯指定的標誌抱怨如果'struct'不存在,因爲它不能識別'FILE'作爲類型 –

+0

@TimCastelijns因爲它是C(不是C++) – Rob

回答

2

刪除struct幷包含stdio.h以獲取typedef。

+0

如果我放棄'struct',編譯器會抱怨因爲'-ansi'標誌,並且之前包含'stdio.h',這只是編譯器投訴的代碼片段 –

+1

@RuiRosário做一個完整的簡短示例,編輯你的問題。還要添加你得到的確切的錯誤信息。 – cnicutar

+0

其實沒有必要這樣做。我更新了我的MinGW,並嘗試在沒有'struct'的情況下進行編譯,並且工作,一定是因爲我從我的大學獲得的gcc版本 –