This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Compiler error when declaring array using constant

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];

I get the same error whether or not I use "code". I've worked around this by using
#define BUF_SIZE 40
but this isn't optimal for style, and debugging purposes.

Has anyone else seen this problem?

Parents
  • BYTE Qbuf[BUF_SIZE];

    BUF_SIZE must be constant not a constant variable. It must be fix at compile time.
    the const keyword does not mean it can not be changed. Therefore thier can not be a style that would suggest a const.

    further more. Overusing of "Style" may result in extra ram / rom usage. your program need to be organize and read able, but not a slave to fashion. Remember just because Keil got C to fit into an 8bit Cpu does not mean you can forget it is an 8bit Cpu

Reply
  • BYTE Qbuf[BUF_SIZE];

    BUF_SIZE must be constant not a constant variable. It must be fix at compile time.
    the const keyword does not mean it can not be changed. Therefore thier can not be a style that would suggest a const.

    further more. Overusing of "Style" may result in extra ram / rom usage. your program need to be organize and read able, but not a slave to fashion. Remember just because Keil got C to fit into an 8bit Cpu does not mean you can forget it is an 8bit Cpu

Children