Skip to content

Instantly share code, notes, and snippets.

@sw17ch
Created October 13, 2009 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sw17ch/209588 to your computer and use it in GitHub Desktop.
Save sw17ch/209588 to your computer and use it in GitHub Desktop.
#include <stdio.h>
// Make a NEWTYPE
#define NT(inner,outer) \
typedef struct \
{ \
inner _nt_field; \
} outer
// Declare a val of NEWTYPE
#define DECLNT(outer,name,init) outer name = { init }
// Inspect the value of a NEWTYPE
#define VALNT(x) (x)._nt_field
NT(short,INT16);
NT(int, INT32);
INT16 increment_16(INT16 v)
{
VALNT(v)++;
return v;
}
INT32 increment_32(INT32 v)
{
VALNT(v)++;
return v;
}
int main(int argc, char * argv[])
{
DECLNT(INT16, i_16, 15);
DECLNT(INT32, i_32, 15);
printf("%d\n", VALNT(i_16));
printf("%d\n", VALNT(i_32));
i_16 = increment_16(i_16);
i_32 = increment_32(i_32);
printf("%d\n", VALNT(i_16));
printf("%d\n", VALNT(i_32));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment