Created
October 13, 2009 21:29
-
-
Save sw17ch/209588 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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