我想做一些簡單的事情,只需將參數傳遞給一個函數,但我似乎遇到了很多麻煩,我似乎無法弄清楚如何解決它。僅供參考這是一個家庭作業,將成爲一個基本的彙編語言模擬器。在函數中與參數衝突的類型C
下面是代碼
char cmd_char;
char leadChar;
int location;
short int value;
words_read = sscanf(cmd_buffer, "%d %c%hx x%hx", &cmd_char, &leadChar, &location, &value);
...
done = execute_command(cmd_char, cpu, leadChar, location, value);
...
int execute_command(char cmd_char, CPU *cpu, char leadChar, int location, int value)
{
...
}
的字符串被輸入到的sscanf(...)要麼是:
m x305f x002c
r r6 x10a5
r r3 x0014
j x3030
沒有與掃描正確的價值觀沒有問題,但是當我將變量leadChar,位置和值作爲參數添加到execute_command,我一直無法成功調用它。看到下面的錯誤。
的錯誤信息
Lab10.c:42:46: error: expected declaration specifiers or '...' be fore '(' token
int execute_command(char cmd_char, CPU *cpu, (char) void, (int) void, (int) voi d);
^
Lab10.c:42:59: error: expected declaration specifiers or '...' be fore '(' token
int execute_command(char cmd_char, CPU *cpu, (char) void, (int) void, (int) voi d);
Lab10.c:277:5: error: conflicting types for 'execute_command'
int execute_command(char cmd_char, CPU *cpu, char leadChar, int location, int v alue)
^
Lab10.c:278:1: note: an argument type that has a default promotio n can't match an empty parameter name list declaration
{
^
Lab10.c:265:20: note: previous implicit declaration of 'execute_c ommand' was here
done = execute_command(cmd_char, cpu, leadChar, location, value);
^
^
Lab10_BenShaughnessy.c:42:71: error: expected declaration specifiers or '...' be fore '(' token
int execute_command(char cmd_char, CPU *cpu, (char) void, (int) void, (int) voi d);
你的函數聲明是否符合你的定義? – Gopi 2014-12-04 05:30:54
在首次使用或包含適當的頭文件之前聲明'int execute_command(char cmd_char,CPU * cpu,char leadChar,int位置,int值);' – 2014-12-04 05:32:23