Enums as Indices

COTTRELL, JAMES cottrell at NBS-VMS.ARPA
Wed Feb 19 10:12:18 AEST 1986


/*
> ---though to my mind using enumerated types as indicies is `treading
> on thin ice' (I have no explanation as to why I feel this way; I
> just do).
> -- 
> In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)

Perhaps I can allay some of your doubts. First, remember that in AWK
subscripts may be string valued. Thus: `/apple/ { x["apple"]++ }' is OK.
Second, I feel that ENUM's are merely a way of writing #defines with a
bit of type checking thrown in (thus the error). One of the things you
can do with integers is use them for subscripts. I can imagine a
statement like `wavelenth[RED] = however_many_angstroms_red_really_is'.
This moves us closer to a database view of things where the sparse
matrix of things like 'RED', 'BLUE', etc., are mapped into small integers.
An expression such as `wavelength['RED'] = ...' is currently legal altho
not recommended (portability). I am reminded of LISP's property lists, 
which are conceptually `indices of arbitrary type.' Another thought
that comes to mind is that struxure members are somewhat enumerated
offset constants for a particular struxure. Remember how they used
to do struxures in FORTRASH? Oh, well, I'm rambling.

	jim		cottrell at nbs
*/
------



More information about the Comp.lang.c mailing list