Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!mailrus!wuarchive!decwrl!bacchus.pa.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com (diamond@tkovoa) Newsgroups: comp.lang.c Subject: Re: Is this bad programming? Keywords: #define array definition Message-ID: <1910@tkou02.enet.dec.com> Date: 9 Aug 90 08:27:03 GMT References: <1990Aug8.100614.1223@resam.dk> Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 47 In article <1990Aug8.100614.1223@resam.dk> andrew@resam.dk (Leif Andrew Rump) writes: >char errortext[][40] = { > "234567890123456789012345678901234567890", >#define FILE_FOOTER_ERROR 1 > "File footer error", >#define DRAW_FOOTER_ERROR 2 > "Draw footer error", >#define GRAP_FOOTER_ERROR 3 > "Grap footer error", >#define BASE_FRAME_CREATE_ERROR 4 > "Base_frame creation error", > } Yes, it is perfectly legal, but as you suggested (and I deleted) it might not be considered aesthetic. >I am a pascal-programmer (aha, that is why :-) ) in my >real life and I could also use union/enumerated types. If you want enumeration types, C almost learned them about 11 years ago. Under ANSI, they've been almost learned in a standardized way. However, you might have problems with pre-ANSI compilers (where a single compiler would often be inconsistent with itself). typedef enum error_t { Filler_to_match_Digit_String, /* I would delete this and the string */ FILE_FOOTER_ERROR, DRAW_FOOTER_ERROR, GRAP_FOOTER_ERROR, BASE_FRAME_CREATE_ERROR, Number_of_Error_Codes /* Put new insertions BEFORE this! */ } error_t; /* If you use Posix, then you can't end it with _t */ char errortext[][40] = { "234567890123456789012345678901234567890", /* I'd make it a comment */ "File footer error", "Draw footer error", "Grap footer error", "Base_frame creation error", } int junk = 1 / (sizeof errortext[0] * Number_of_Error_Codes == sizeof errortext); /* A compile-time error here means mismatched quantities */ -- Norman Diamond, Nihon DEC diamond@tkou02.enet.dec.com This is me speaking. If you want to hear the company speak, you need DECtalk.