1

This is my header file:

typedef int* Arg;   
typedef int* Args[];
typedef int** ArgsList[];

typedef int (*ProcessStart)(Args);

typedef struct PCBEntry{

    ProcessStart proc;
    Args args;
    int pid;
    int curr_proc;
    int sched_info;
    int pc;

} PCBEntry;

I get the error on the Args argsline in the struct and I have no idea why.

0

2 Answers 2

3

Because you defined Args as int *[], the member args is effectively declared as

int *args[];

This is a flexible array member, and they are only allowed at the end of a structure.

If you meant to imply that Args was a pointer (in the same vein as char **argv), declare it as a pointer:

typedef int **Args;
Sign up to request clarification or add additional context in comments.

11 Comments

"You can't put a "variable-sized array" in a struct" - except if you have a C99 compiler and you put the variable sized array to the end of the struct.
@H2CO3 Strictly, a flexible array member is not a variable length array. You can't put a VLA into a struct.
You're suggesting changing Args from an array type to a pointer type. That might be a good solution, but it's a big change to the structure.
Args isn't a VLA type. A VLA has a specified non-constant size; Args doesn't have a specified size at all.
Thanks all for your comments; I rewrote the answer to be clearer.
|
0

Rather than using

typedef int* Args[];

and in your structure declaration

Args args;

you would be better served to just use the first type for your structure declaration...

Arg args[];

To be honest, I'm not even sure the the first one is a legal typedef, but it's only that I've never ever done anything like that with a typedef before. My gut tells me that it's not legal and therefore Args is undefined and thus the error you're getting. If I apply the right-left rule to that, then Args is a type that is an array of pointers to int... so, maybe it's legal, but it sure reads funny to my eye.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.