简体   繁体   中英

C language. Declaration of the array, size of which is given by the macros #define

I wonder why when I try to declare the array using #define I get errors from compiler, while using literal instead of the size allows me to do so.

some_name.h:

#define size 10;

int* waitingBench[size];

What you have will be pre-processed to:

int* waitingBench[10;];
//                  ^ notice this guy!

Remove the semicolon from the #define .

(And size is a really bad identifier to #define .)

Remove the ; from your definition. As you currently have it, this is equivillent to int* waitingBench[10;]; which you know is incorrect.

Macro definitions are not C instructions, so they do not need to be terminated with a semi-colon (and they must not exceed one line unless a line continuation backslash is used, and they must not share the line with something else).

Remove ";" in the end:

#define size 10

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM