Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

How to implement class and method in C? (e.g. Linux Kernel) [duplicate]

$
0
0

This question already has an answer here:

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?


Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>