Skip to content

Instantly share code, notes, and snippets.

View manuel-fischer's full-sized avatar

Manuel Fischer manuel-fischer

  • Ruhr Universität
View GitHub Profile

X-lists in C++

X-lists provide a simple mechanism to enumerate tabular information in one place of the source code, without loosing flexibility.

Defining X-lists

#define FRUITS(X) \
    /*   name        color */ \
    X(orange,       0xff8000) \
    X(green_apple,  0x00ff00) \
    X(red_apple,    0xff0000) \
@manuel-fischer
manuel-fischer / offsetof.md
Last active March 18, 2021 20:14
Using offsetof

Using offsetof

offsetof is useful in typeless code and "reflection".

#include <stddef.h> // -> offsetof macro

Using offsetof with typeless code

API based on offsetof

Lets write a function that searches linearily for an element by a given key.