Source File Organization

Lee Derbenwick lfd at cbnewsm.att.com
Thu Feb 28 05:55:09 AEST 1991


In article <1991Feb27.182525.29758 at cbnewsm.att.com>,
I gave a trick for keeping stuff in sync; but I left commas out of
the two macro definitions (SORRY ABOUT THAT!):
> 
> letters.h contains:
> 
>   LETTER(A, 'A')
>   LETTER(B, 'B')
>   LETTER(C, 'C')
>   LETTER(D, 'D')
>   #undef LETTER
> 
> Then, to get your two examples:
> 
/*
>   #define LETTER(A,B) A
*/
    #define LETTER(A,B) A,	/* should have been */
>   typedef enum {
>   #include "letters.h"
>   } CMD;
> 
/*
>   #define LETTER(A,B) B
*/
    #define LETTER(A,B) B,	/* should have been */
>   char ltrs[] = {
>   #include "letters.h"
>   };

This trick relies on C allowing a trailing comma in an enum or
initializer list; this and other machine-generated C code were
the reasons that the trailing comma _is_ allowed.

 -- Speaking strictly for myself,
 --   Lee Derbenwick, AT&T Bell Laboratories, Warren, NJ
 --   lfd at cbnewsm.ATT.COM  or  <wherever>!att!cbnewsm!lfd



More information about the Comp.lang.c mailing list