sample1b.c

00001 /*
00002  * sample1b.c
00003  */
00004 #include <stdio.h>
00005 
00006 /* What I store my data as... */
00007 struct MyData
00008 {
00009     int value;
00010     const char* myStr;
00011 };
00012 
00013 #define MyData(mbr) \
00014     mbr( theFirst, 35, "Buggrit" ) \
00015     mbr( theSecond, 42, "Millennium" ) \
00016     mbr( theThird, 11, "Hand" ) \
00017     mbr( theFourth, 1, "Shrimp" ) \
00018 
00019 /* What I find my data with... */
00020 enum MyEnum
00021 {
00022 #define extEnum( e, v, s ) e,
00023     MyData(extEnum)
00024     MyEnumCount
00025 };
00026 
00027 /* Might want to trace enum values */
00028 const char* szzMyEnum[] = 
00029 {
00030 #define extEnumStr( e, v, s ) #e,
00031     MyData(extEnumStr)
00032 };
00033 
00034 
00035 /* What I put my data in... */
00036 const struct MyData myDataList[] = 
00037 {
00038 #define extData( e, v, s ) { v, s },
00039     MyData(extData)
00040 };
00041 
00042 /* Do something arbitrary with my data */
00043 void MyDataPrint( enum MyEnum e )
00044 {
00045     const struct MyData* found = myDataList + e;
00046     printf( "%d - %s\n", found->value, found->myStr );
00047 }
00048 
00049 int main( void )
00050 {
00051 #define extTest( e, v, s ) MyDataPrint( e );
00052     MyData(extTest)
00053     return 0;
00054 }
00055 

Generated on Fri Jan 2 15:28:34 2009 for Squat by  doxygen 1.5.6