Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!aspect!dave From: dave@aspect.UUCP (Dave Corcoran) Newsgroups: comp.lang.c Subject: Re: Enumerated types... what's the point? Summary: $00.02 contribution using m4 Keywords: enums,#define,m4 Message-ID: <554@aspect.UUCP> Date: 27 Mar 90 14:53:39 GMT References: <1990Mar22.053148.10351@ncsuvx.ncsu.edu> <159@caslon.cs.arizona.edu> <2308@plx.UUCP> Distribution: usa Organization: Aspect Telecommunications, San Jose, Ca Lines: 54 In article <2308@plx.UUCP>, evan@plx.UUCP (Evan Bigall) writes: > >In article <1990Mar22.053148.10351@ncsuvx.ncsu.edu>, dks@shumv1.uucp (D. K. Smith) writes: > >Of course, order is important. So, you type out 100 #defines. Ok, fine. > >Suddenly, you discover you need a new symbol, which should go between the > >third and forth symbols. If you use defines, you are pretty much stuck > >retyping the values on 97 defines. one reason I like macro assemblers :-) > > I hate to do this, but this is what emacs is all about. > The following function (probably poor): > > [ solution using emacs deleted ] here's my contribution using m4 script/definition file: divert(-1) define(LINE,0) define(bump,`define(`LINE',incr(LINE))') define(offset,``#define' $1 LINE bump') define(init,`define(`LINE',$1)') divert /* <> */ source file: init(1) offset(one) offset(two) offset(three) init(0) offset(won) offset(too) offset(tree) result: /* <> */ #define one 1 #define two 2 #define three 3 #define won 0 #define too 1 #define tree 2 -- David C. uunet!aspect!dave