Skip to content

Instantly share code, notes, and snippets.

Last active January 3, 2016 02:29
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
// "chkd_array_factory_head.h"
// Guards to ensure we don't reuse an old list of types
#error "CHKD_ARRAY_TYPES defined before included header"
#error "CHKD_ARRAY_PRIMITIVE_TYPES defined before included header"
#include "generic_defs.h"
// Expansion macro for checked array struct with typename T_NM
#define CHKD_ARRAY(T_NM) TYPED_STRUCT(chkd_array, T_NM)
// Expansion macros for functions on chkd_arrays with typename T_NM
#define CREATE(T_NM) TYPED_FN(chkd_array, T_NM, create)
#define IS_EQUAL(T_NM) TYPED_FN(chkd_array, T_NM, is_equal)
#define SET(T_NM) TYPED_FN(chkd_array, T_NM, set)
#define GET(T_NM) TYPED_FN(chkd_array, T_NM, get)
#define DESC(T_NM) TYPED_FN(chkd_array, T_NM, desc)
// Declaration of the checked array typed struct and functions.
T *data; \
unsigned length; \
T err_val; \
}; \
static CHKD_ARRAY(T_NM) * CREATE(T_NM)(unsigned length, T *err_val); \
static inline bool IS_EQUAL(T_NM)(T *first, T *second); \
static inline T SET(T_NM)(CHKD_ARRAY(T_NM) * self, unsigned idx, T *val); \
static inline T *GET(T_NM)(CHKD_ARRAY(T_NM) * self, unsigned idx); \
static inline char *DESC(T_NM)();
// Used later to declare the checked array for ALL_TYPES.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment