Reputation: 2343
I am working on a homework assignment.
I'm running into the title error in this assignment. From what I've looked into so far, I know that there's a problem with the struct definition somewhere, but because that was done by my professor, I am inclined to think that it's something to do with the way I am calling the struct. Here is the relevant code.
in main.c (where I'm getting the errors from):
#include "processes.h"
//...
Processes * proc = proc_create(filename); //line 90
// the struct I'm trying to create
//...
for(i = 0; i < proc->size; i++) // line 100, where I get the first error of
// dereferencing pointer to an incomplete type
{
//Some code
}
in processes.c (where struct Processes is defined):
struct Processes{
struct Proc *array; // array of Processes
int internal_size; // how big the array is total
int size; // how many valid Procs in the array
};
in processes.h:
typedef struct Processes Processes;
// Create your Processes struct using the filename of a schedule.txt
Processes * proc_create(char *filename);
If someone could please explain to me, exactly what this error means, and point me in the right direction to fixing it, that would be greatly appreciated! Also, If you need anything else, I'm happy to post other code. I was just pretty sure that this was the relevant code.
Upvotes: 1
Views: 301
Reputation:
Since the header file doesn't contain the complete definition of the Processes
struct (only a forward declaration), the compiler cannot possibly know how to access its members. Consequently, proc->size
isn't meaningful inside the main.c file. You will have to move the entire definition of the struct into the header file if you want to use its members directly. (Or, if creating an opaque type is your concern, then write an accessor function that simply returns proc->size
.)
Also, your proc_create()
function should probably take a const char *
argument.
Upvotes: 4