错误: ,预期
一段时间以来,我一直试图找出这段代码的问题所在,但没有成功:
#include"ec.h"
#include"pantalla.h"
#include"so.h"
#define NPROC 20
WORD flags;
void (*rsi_ck)();
char idproces = 'a';
tPCB *pRUN, *pRDY;
tPCB pcbs[NPROC];
char arterisc[]="|/-\\";
void crearProces (tcpb *pcb,PTR funcio)
{
pcb->IdProces = (int) idproces;
a=a+1;
pcb->Estat = RDY;
pcb->Flags = flags;
pcb->CS = Segment(funcio);
pcb->IP = Desplacament(funcio);
pcb->SS_SP =(long)(&(pcb->Pila[MIDA_PILA-12]));
pcb->Pila[MIDA_PILA-11]=Segment(&pRUN);
pcb->Pila[MIDA_PILA-1]=512;
pcb->Pila[MIDA_PILA-2]=pcb->CS;
pcb->Pila[MIDA_PILA-3]=pcb->IP;
}
//more rows below
它在第 16 行给了我一个编译错误“,预期”,其中定义了函数“CrearProces”。我尝试将函数的定义移动到任何其他行,错误只是“跟随”它。
提前致谢。
编辑:tPCB 定义如下:
typedef struct
{
LONG IdProces;
WORD Estat;
LONG SS_SP;
WORD Quantum;
WORD Prioritat;
WORD Flags;
WORD CS;
WORD IP;
WORD Pila[MIDA_PILA];
} tPCB;
I've been trying to figure out what's wrong with this code without success for a while:
#include"ec.h"
#include"pantalla.h"
#include"so.h"
#define NPROC 20
WORD flags;
void (*rsi_ck)();
char idproces = 'a';
tPCB *pRUN, *pRDY;
tPCB pcbs[NPROC];
char arterisc[]="|/-\\";
void crearProces (tcpb *pcb,PTR funcio)
{
pcb->IdProces = (int) idproces;
a=a+1;
pcb->Estat = RDY;
pcb->Flags = flags;
pcb->CS = Segment(funcio);
pcb->IP = Desplacament(funcio);
pcb->SS_SP =(long)(&(pcb->Pila[MIDA_PILA-12]));
pcb->Pila[MIDA_PILA-11]=Segment(&pRUN);
pcb->Pila[MIDA_PILA-1]=512;
pcb->Pila[MIDA_PILA-2]=pcb->CS;
pcb->Pila[MIDA_PILA-3]=pcb->IP;
}
//more lines below
It gives me a compilation error, ", expected" on line 16, where the function "CrearProces" is defined. I've tried to move the definition of the function to any other line and the error just "follows" it.
Thanks in advance.
Edit: tPCB is defined as follows:
typedef struct
{
LONG IdProces;
WORD Estat;
LONG SS_SP;
WORD Quantum;
WORD Prioritat;
WORD Flags;
WORD CS;
WORD IP;
WORD Pila[MIDA_PILA];
} tPCB;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
void crearProces (tcpb *pcb,PTR funcio)
中的“tcpb”是什么?它应该是tPCB
吗?What's a "tcpb" in
void crearProces (tcpb *pcb,PTR funcio)
? Should it be atPCB
?由于历史原因,C 语言支持两种风格的函数声明(和定义)。
“新”基于原型的风格
和“旧”K&R 风格
当编译器看到
()
中的第一个标识符是已知类型名称时,它假设该函数是用原型定义的。当编译器发现()
中的第一个标识符不是已知的类型名称时,它假定该函数是用旧的 K&R 风格定义的。在后一种情况下,每个标识符必须与下一个标识符用,
分隔。在您的情况下,函数定义将
tcpb
作为()
中的第一个标识符。显然你的程序中没有这样的类型,这使得编译器假设这不是类型名称,而是 K&R 样式定义中的参数名称。因此,它后面必须跟有,
。这显然不是你的本意。
那么,什么是
tcpb
?当程序中没有此类类型时,为什么要使用它作为类型名称?PS 不同的编译器可以使用不同的方法来识别无效代码。因此,它们可以以不同的方式检测相同的错误并发出不同的诊断消息。显然您的特定编译器正在使用我上面描述的逻辑。因此会出现有关逗号的错误消息。另一个编译器可能会以不同的方式报告相同的错误。
For historical reasons C language supports two styles of function declarations (and definitions).
The "new" prototype-based style
And the "old" K&R style
When the compiler sees that the first identifier in
()
is a known type name, it assumes that the function is defined with prototype. When the compiler sees that the first identifier in()
is not a known type name, it assumes that the function is defined in old K&R style. In the latter case each identifier must be separated from the next one by,
.In your case the function definition has
tcpb
as the first identifier in()
. Apparently there's no such type in your program, which makes the compiler to assume that this is not a type name but rather a parameter name in a K&R style definition. As such it must be followed by a,
.This is obviously not your intent.
So, what is
tcpb
? Why are you using it as a type name when there's no such type in your program?P.S. Different compilers can use different approaches to recognize invalid code. For that reason, they can detect the same error differently and issue different diagnostic messages. Apparently your specific compiler is using the logic I described above. Hence the error message about a comma. Another compiler might report the same error differently.