尝试在结构内部使用C函数指针时出现错误(该函数只是将第一个元素从链接列表中弹出并返回该元素):
main.c:在函数“ simulation”中:main.c:279:错误:不兼容 从“ PROCESS”类型分配为“ struct PROCESS *”类型时的各种类型
我的代码是这样的:
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);
任何帮助将不胜感激!
答案 0 :(得分:1)
您的next
结构字段是struct PROCESS *
,您的函数返回一个PROCESS
。使它们具有相同的类型,它将起作用。
typedef struct PROCESS *(*Get) (PROCESS *head);
typedef PROCESS *(*Get) (PROCESS *head);