TLDR: Structure Composition and Emulating Inheritance in C
Date: 2020-06-07 Source: https://arpitbhayani.me/blogs/inheritance-c
Overview
Emulate inheritance in C using structure composition! Learn how it enables code extensibility, powering Linux Kernel & Python. C language does not support inheritance however it does support Structure Compositions which can be tweaked to serve use-cases requiring parent-child relationships.
Key Points
- C language does not support inheritance however it does support Structure Compositions which can be tweaked to serve use-cases requiring parent-child relationships.
- Memory Representation of
list_int: Structures in C are not padded and they do not even hold any meta information, not even for the member names; hence during allocation, they are allocated the space just enough to hold the actual data. ! In the illustration above we see how members of list_int are mapped on the allocated space - required by its individual members.