错误: ,预期

发布于 2024-10-20 21:44:37 字数 997 浏览 3 评论 0原文

一段时间以来,我一直试图找出这段代码的问题所在,但没有成功:

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拥抱影子 2024-10-27 21:44:37

void crearProces (tcpb *pcb,PTR funcio) 中的“tcpb”是什么?它应该是tPCB吗?

What's a "tcpb" in void crearProces (tcpb *pcb,PTR funcio)? Should it be a tPCB?

笑梦风尘 2024-10-27 21:44:37

由于历史原因,C 语言支持两种风格的函数声明(和定义)。

“新”基于原型的风格

void foo(int a, short b, double c)
{
  ...

和“旧”K&R 风格

void foo(a, b, c)
int a;
short b;
double c;
{
  ...

当编译器看到 () 中的第一个标识符是已知类型名称时,它假设该函数是用原型定义的。当编译器发现 () 中的第一个标识符不是已知的类型名称时,它假定该函数是用旧的 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

void foo(int a, short b, double c)
{
  ...

And the "old" K&R style

void foo(a, b, c)
int a;
short b;
double c;
{
  ...

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文