I am watching Linux kernel code, and found some C codes that behaves like classes in objected oriented programming.
Example:
const struct sched_class fair_sched_class = {
.next = &idle_sched_class,
.enqueue_task = enqueue_task_fair,
.dequeue_task = dequeue_task_fair,
.yield_task = yield_task_fair,
.yield_to_task = yield_to_task_fair,
.check_preempt_curr = check_preempt_wakeup,
.pick_next_task = pick_next_task_fair,
.put_prev_task = put_prev_task_fair,
};
Let's suppose some functions like enqueue_task_fair
are already implemented above.
How does above code work? What does the .
operator do within the initialization body?
Could you give me an example how to use struct sched_class
in the main function?