I've been trying to开发者_JS百科 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;
What's a "tcpb" in void crearProces (tcpb *pcb,PTR funcio)
? Should it be a tPCB
?
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.
精彩评论