0

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?

jxh
  • 69,070
  • 8
  • 110
  • 193
invictus
  • 81
  • 5
  • 1
    [Dynamic method dispatching in C](http://stackoverflow.com/q/17621544/315052). – jxh Apr 28 '17 at 07:10
  • Then, what does `.` operator within the struct phrase does? Does it refer to the member variable of the struct? Example: ```.next = &idle_sched_class``` – invictus Apr 29 '17 at 08:10

0 Answers0