cpiber / cest

Simple inheritance in C

Repository from Github https://github.comcpiber/cestRepository from Github https://github.comcpiber/cest

cest

Inheritance in C.

This program, similarly to the standard preprocessor, can take a file and produce valid C syntax, providing inheritance features.

Getting started

  1. Clone this repo
  2. Compile and view help:
$ make
$ ./cest -h

See examples for more info.

Syntax

Currently only a single parent is supported. Support for multiple parents is planned.

Declare struct child to inherit from struct Base:

struct Child (struct Base) {
  // child members
};

Currently using any struct present in the current file and its includes is possible, as well as names from direct typedefs (i.e. typedef struct ... name;). Support for separate typedefs is planned.

The special name CEST_MACROS_HERE is used to denote the place where the casting-macros should be placed.

The macros allow type-safe casting of child-structs to their parent structs. They are of the form CEST_AS_<typename>, where <typename> can be struct_<structname> or the typedef'd name. S may be appended for the pointer version.

Integrating into the build

Since this tool is not part of the regular C-toolchain, it needs to be called separately. Using a build tool like GNU Make or CMake, the following approach can be used:

  1. Instruct build tool to transform .h.in files and place them in build folder as .h
  2. Setup up build folder for includes, or directly include from there

About

Simple inheritance in C

License:MIT License


Languages

Language:C 97.1%Language:Makefile 2.9%