Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnews!cbnewsm!lfd From: lfd@cbnewsm.att.com (Lee Derbenwick) Newsgroups: comp.lang.c Subject: Re: Source File Organization Summary: correction on trick - wrong macro definitions Message-ID: <1991Feb27.185509.1452@cbnewsm.att.com> Date: 27 Feb 91 18:55:09 GMT References: <1991Feb26.045242.23453@rfengr.com> <1991Feb27.182525.29758@cbnewsm.att.com> Organization: AT&T Bell Laboratories Lines: 37 In article <1991Feb27.182525.29758@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@cbnewsm.ATT.COM or !att!cbnewsm!lfd