Is this bad programming?
diamond@tkovoa
diamond at tkou02.enet.dec.com
Thu Aug 9 18:27:03 AEST 1990
In article <1990Aug8.100614.1223 at resam.dk> andrew at 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 at tkou02.enet.dec.com
This is me speaking. If you want to hear the company speak, you need DECtalk.
More information about the Comp.lang.c
mailing list