I am attempting to take RRhead, have a new RCB point at RRhead as it's next, and have RRhead point at the new RCB as it's prior.
typedef struct{
int sequence_number;
int file_descriptor;
FILE *requested_file;
int bytes_remaining;
int quantum;
struct RCB *next;
struct RCB *prior;
} RCB;
typedef struct RCB RCB;
RCB *RRhead = NULL;
static void admit_to_scheduler_RR(int fd, FILE *fin){
int sequence_counter, new_bytes_remaining, new_quantum = 0;
RCB new_rcb = {sequence_counter, fd, fin, new_bytes_remaining, new_quantum, RRhead, NULL};
RRhead->prior = &new_rcb;
RRhead = &new_rcb;
sequence_counter++;
}
producing the following errors:
sws.c: In function ‘admit_to_scheduler_RR’:
sws.c:318:10: error: variable ‘new_rcb’ has initializer but incomplete type
struct RCB new_rcb = {sequence_counter, fd, fin, new_bytes_remaining, new_quantum, RRhead, NULL};
^
sws.c:318:10: warning: excess elements in struct initializer [enabled by default]
sws.c:318:10: warning: (near initialization for ‘new_rcb’) [enabled by default]
sws.c:318:10: warning: excess elements in struct initializer [enabled by default]
sws.c:318:10: warning: (near initialization for ‘new_rcb’) [enabled by default]
sws.c:318:10: warning: excess elements in struct initializer [enabled by default]
sws.c:318:10: warning: (near initialization for ‘new_rcb’) [enabled by default]
sws.c:318:10: warning: excess elements in struct initializer [enabled by default]
sws.c:318:10: warning: (near initialization for ‘new_rcb’) [enabled by default]
sws.c:318:10: warning: excess elements in struct initializer [enabled by default]
sws.c:318:10: warning: (near initialization for ‘new_rcb’) [enabled by default]
sws.c:318:10: warning: excess elements in struct initializer [enabled by default]
sws.c:318:10: warning: (near initialization for ‘new_rcb’) [enabled by default]
sws.c:318:10: warning: excess elements in struct initializer [enabled by default]
sws.c:318:10: warning: (near initialization for ‘new_rcb’) [enabled by default]
sws.c:318:14: error: storage size of ‘new_rcb’ isn’t known
struct RCB new_rcb = {sequence_counter, fd, fin, new_bytes_remaining, new_quantum, RRhead, NULL};
^
sws.c:319:9: error: dereferencing pointer to incomplete type
RRhead->prior = &new_rcb;
^
I have no clue about why I am getting the warnings for excess elements. Am I not initializing new_rcb correctly? Do I need to create it and then set all of the fields to what I want?
I believe this all has to do with having an "incomplete type" for new_rcb. Most googling indicates that this is because the compiler doesn't know what the size of RCB should be. It seems to indicate that I need to place this struct definition into a header. Is this absolutely necessary?