The following code generates a this error when compiled: C51 COMPILER V6.02 - SN: XXXXX-XXXXX COPYRIGHT KEIL ELEKTRONIK GmbH 1987 - 1999 *** ERROR C221 IN LINE 7 OF QUEUE_I.H: non-constant case/dim expression
const unsigned char code BUF_SIZE = 40; BYTE Qbuf[BUF_SIZE];
#define BUF_SIZE 40
"but this isn't optimal for style" So you prefer "style" over the language syntax rules, then...? ;-)
The third major alternative for declaring integer constants is to use an enum. This is of course most useful for grouping a related series of constants, rather than individual ones. But enum values can be used to size arrays:
typedef enum { ThingOne, ThingTwo, NumThings } Thing; U16 thingRefCount[NumThings];
"const in ANSI C isn't really a compile-time constant" As is obvious from a quick look at at string.h:
extern char *strchr (const char *s, char c); extern int strpos (const char *s, char c); extern char *strrchr (const char *s, char c); extern int strrpos (const char *s, char c);