Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active December 27, 2016 14:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/d3f49fbce27204b8ba6b3d3ea8e3dafc to your computer and use it in GitHub Desktop.
Save pervognsen/d3f49fbce27204b8ba6b3d3ea8e3dafc to your computer and use it in GitHub Desktop.
typedef union {
struct { char pad_x[31]; int x; } __attribute__((packed));
struct { char pad_y[512]; int y; } __attribute__((packed));
// ...
} __attribute__((packed)) overlay;
// Macrofied:
#define JOIN1(x, y) x##y
#define JOIN(x, y) JOIN1(x, y)
#define FIELD_OFFSET(field, offset) struct { char JOIN(pad, __LINE__)[offset]; field; } __attribute__((packed))
typedef union {
FIELD_OFFSET(int x, 31);
FIELD_OFFSET(int y, 500);
// ...
} __attribute__((packed)) overlay;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment