views:

230

answers:

4

Edit 2

Thanks for all the suggestions, I edited the code below from the suggestions given. However, it still doesnt seem to compile. But nevertheless, thanks a lot for the help hands.

Edit

I apologize for not putting the pcb struct into the code snippet. There is a struct called pcb defined in above the two structs I originally posted. Namely,

typedef struct pcb{
    UINT32 proc;
    struct pcb *link;
}pcb;

Hi,

I asked a question regarding structs in C a few minutes ago and got an answer blazing fast. But now I'm facing another problem, namely the error in the title of this question. I'm trying to implement a simple priority queue in C using arrays of queues. However, when I try to declare a function on pcb_pQ structure, I get the above error. I have the structs clearly defined in the heard file.

In the header file:

typedef struct pcb_Q{
    pcb *head;
    pcb *tail;
    SINT32 size;
} pcb_Q;

typedef struct pcb_pQ {
 pcb_Q queues[5];
 SINT32 size;
} pcb_pQ;

Function prototype in header file:

/*priority queue operations*/
VOID pcb_pq_enqueue(pcb_pQ*, pcb*);

Function impelmentation in .c file:

VOID pcb_pq_enqueue(pcb_pQ* pcb_pQ_p, pcb* pcb_p) {
 pcb_Q* pcb_Q_p;
 int priority;

 priority = pcb->proc_priority;
 pcb_Q_p = &pcb_pQ->queues[priority];

 pcb_enqueue(pcb_Q_p, pcb);
}

When I try to compile the above code, I get an "error: expected ')' before '*' token". This error is pointing to the function signature in the .c file, namely

VOID pcb_pq_enqueue(pcb_pQ* pcb_pQ_p, pcb* pcb_p) {

But I am not sure why I am getting this error, could someone give me a hand? Thanks a lot.

+1  A: 

Are you including the header file? Barring misspellings, that error is almost invariably caused by a missing typedef.

In other words, the compiler doesn't know about either the pcb_pQ or pcb type (or both).


Edit: There's something else wrong because this compiles fine:

qq.h
    typedef struct pcb {
        unsigned int proc;
        struct pcb *link;
    } pcb;

    typedef struct{
        pcb *head;
        pcb *tail;
        int size;
    } pcb_Q;

    typedef struct pcb_pQ {
        pcb_Q queues[5];
        int size;
    } pcb_pQ;

    void pcb_pq_enqueue(pcb_pQ*, pcb*);

qq.c:
    #include <stdio.h>
    #include "qq.h"
    void pcb_pq_enqueue(pcb_pQ *pcb_pQ, pcb *pcb) {}
    int main (void) { return 0; }

I had to use other types (and I modified the pcb structure to be a named one - I'm not sure your given one should have compiled since as-is since there is no struct pcb type in existence).


Based on all the comments and answers to date, I'm pretty certain there's something wrong with your compiler. GCC compiles that snippet above just fine.

Try putting my two files above onto your system and seeing if they compile okay.

And be aware that you do need to name your pcb structure. See here for the gory details but the consensus seems to be that

    typedef struct {
        unsigned int proc;
        struct pcb *link;
    } pcb;

will define a struct pcb incomplete type which is a distinct type from pcb (and the structure you're currently defining).

paxdiablo
yes, i am including the header file
lhw
Did you notice the caps in the code he pasted, in particular VOID and UINT32?
Tim Post
thanks for trying it out, now im thinking it may be a compiler issue.. i am using a cross-compiler, not the usual gcc.
lhw
@Tim, I noticed that but, if they weren't declared properly, he would have gotten an error in the header file, not the C file.
paxdiablo
@paxdiablo, Sorry, I did not catch the prototype.
Tim Post
Compiled fine for me too, under gcc and clang, surprisingly leaving pcb unnamed didn't give any warnings. @lhw does this give you any errors when using your cross compiler?
Scott Wales
A: 

It looks like the compiler doesn't find the defintion of pcb.

Andreas Brinck
A: 

First, it is 'void' not 'VOID' until or unless you have definition like

#define VOID void

This can be better if

typedef struct tag_struct_pcb_Q {
    pcb *head;
    pcb *tail;
    SINT32 size;
} pcb_Q;

typedef struct tag_structpcb_pQ {
 pcb_Q queues[5];
 SINT32 size;
} pcb_pQ;

modern 'C' compiler expect the return type must be mentioned.

If you have definition like this also cause error.

#define VOID

Another possibility

VOID pcb_pq_enqueue(pcb_pQ* pcb_pQ, pcb* pcb) {

where does pcb is from? it is not good to have pcb* pcb. ALWAYS give different name for variable type and variable name

Gopalakrishnan Subramani
yes it actually is defined in another definition file, thanks for the answer though
lhw
I saw the same thing at first, however, he's getting the error when compiling the c file. If `VOID` was broken, he would have gotten the error in the header as soon as it saw the function prototype.
Tim Post
A: 

Change:

typedef struct{
    UINT32 proc;
    struct pcb *link;
}pcb;

to:

typedef struct pcb {
    UINT32 proc;
    struct pcb *link;
} pcb;
Paul R
Why wouldn't that throw an error in the header, though? I think he may have a broken compiler.
Tim Post