I'm getting an error when I try to use a C function pointer inside of a struct (the function just pops the first element off of a linked list and returns the element):
main.c: In function ‘simulation’: main.c:279: error: incompatible types when assigning to type ‘struct PROCESS *’ from type ‘PROCESS’
My code is this:
typedef struct PROCESS {
struct PS_TABLE *tbl_ref;
int pid;
int time_in_prev_state;
int state_ts;
int static_prio;
int dynamic_prio;
int cpu_rem;
struct PROCESS *next;
} PROCESS;
typedef void (*Add) (PROCESS *head, PROCESS *new_ps);
typedef PROCESS (*Get) (PROCESS *head);
typedef struct SCHEDULER {
int quantum;
sched_t sch_alg;
Add add_process;
Get get_next_process;
} SCHEDULER;
PROCESS *fcfs_get_next_proc(PROCESS **head) { //POP
PROCESS *tmp = head;
head = tmp->next;
tmp->next = NULL;
return tmp;
}
SCHEDULER *scheduler_obj = malloc(sizeof(SCHEDULER));
scheduler_obj->get_next_process = fcfs_get_next_proc;
PROCESS *RUNNING_PROCESS = NULL;
RUNNING_PROCESS = scheduler->get_next_process(head_proc);
Any help would be really appreciated!
typedef PROCESS* (*Get) (PROCESS *head);
PROCESS *tmp = head; head = tmp->next;
should bePROCESS *tmp = *head; *head = tmp->next;