我想做一些简单的事情,只需将参数传递给一个函数,但我似乎遇到了很多麻烦,我似乎无法弄清楚如何解决它。仅供参考这是一个家庭作业,将成为一个基本的汇编语言模拟器。在函数中与参数冲突的类型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