Source File Organization

Mark Harrison harrison at necssd.NEC.COM
Thu Feb 28 06:07:43 AEST 1991


In article <1991Feb26.045242.23453 at rfengr.com>,
rfarris at rfengr.com (Rick Farris) writes:

> I have an enumerated type:
> typedef enum { A, B, C, D } CMD;
> 
> and a corresponding array of ascii representations :
> char ltrs[] = { 'A', 'B', 'C', 'D' };
> 
> My problem is: How do I keep the darn things in sync?

One way:  Have a definition file that builds a header file
with the typedef and a C file with the array.  I have used
this method successfully for things like symbol table string
constants and error messages.

Example:

file foo.def
------------
CMD:	A B C D
TOKENS:	Q X Y

generates foo.h:
----------------
typedef enum { A, B, C, D } CMD;
typedef enum { Q, X, Y } TOKENS;

and foo.c:
----------
char CMD_ltrs[] = { 'A', 'B', 'C', 'D' };
char TOKENS_ltrs[] = { 'Q', 'X', 'Y' };

Awk and Perl are good languages for building tools like this.
-- 
Mark Harrison             harrison at necssd.NEC.COM
(214)518-5050             {necntc, cs.utexas.edu}!necssd!harrison
standard disclaimers apply...



More information about the Comp.lang.c mailing list