Skip to content

Instantly share code, notes, and snippets.

@ghazel
Created February 1, 2015 00:13
Show Gist options
  • Save ghazel/c4970537e1b7456c9755 to your computer and use it in GitHub Desktop.
Save ghazel/c4970537e1b7456c9755 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <assert.h>
#include <inttypes.h>
struct hidden_data {
char * stuff;
uint8_t foo;
uint16_t bar;
uint32_t baz;
};
#define _GEN_ACCESSOR(valname) \
extern inline const typeof(((struct hidden_data *)0)->valname) \
hidden_data_get_ ## valname(struct hidden_data * h) { \
assert(h != NULL); \
return h->valname; \
}
_GEN_ACCESSOR(stuff)
_GEN_ACCESSOR(foo)
_GEN_ACCESSOR(bar)
_GEN_ACCESSOR(baz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment