Enumerated types... what's the point?

Dave Corcoran dave at aspect.UUCP
Wed Mar 28 00:53:39 AEST 1990


In article <2308 at plx.UUCP>, evan at plx.UUCP (Evan Bigall) writes:
> >In article <1990Mar22.053148.10351 at ncsuvx.ncsu.edu>, dks at 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
/* <<m4>> */

source file:

init(1)
offset(one)
offset(two)
offset(three)
init(0)
offset(won)
offset(too)
offset(tree)

result:

/* <<m4>> */

#define one 1 
#define two 2 
#define three 3 

#define won 0 
#define too 1 
#define tree 2 

--

David C.
uunet!aspect!dave



More information about the Comp.lang.c mailing list