Source File Organization

Bob Kitzberger @sation rlk at telesoft.com
Thu Feb 28 13:45:10 AEST 1991


Rick Farris writes:

> typedef enum { A, B, C, D } CMD;
> 
> and a corresponding array of ascii representations :
> 
> char ltrs[] = { 'A', 'B', 'C', 'D' };

Yes, you asked for a C solution, but since this was cross-posted to
comp.software-eng I thought I'd point out Ada's solution to this.
The example below specifies a type 'color', and a call to a language-defined
attribute of this prefix, 'IMAGE. 

with text_io;
procedure foo is
  type color is (red, green, blue );
  my_color : color := green;
begin
  text_io.put_line( color'image(my_color) );
end foo;

All enumerated types have a corresponding 'IMAGE attribute, which implies 
that an ASCII (or EBCDIC ;-) representation of each enumerated value be 
present at execution time.  These image tables may be supressed at compile 
time.

	.Bob.
-- 
Bob Kitzberger               Internet : rlk at telesoft.com
TeleSoft                     uucp     : ...!ucsd.ucsd.edu!telesoft!rlk
5959 Cornerstone Court West, San Diego, CA  92121-9891  (619) 457-2700 x163
------------------------------------------------------------------------------
"Wretches, utter wretches, keep your hands from beans!"	-- Empedocles



More information about the Comp.lang.c mailing list