0

I tried to run this code:

#define ROW_CNT 8;
#define COLUMN_CNT 24;
#define FIRST_COLUMN 2;

unsigned int volume[ROW_CNT][COLUMN_CNT][ROW_CNT];

but I get the following errors:

expected identifier or '(' before ']' token

Why is that?

3 Answers 3

4

Take off the semicolons on your #defines.

The #define directives are handled by the preprocessing stage of compilation, which is all about text substitution. So, whenever the preprocessor performs text substitution, your program becomes

unsigned int volume[8;][24;][2;];

which isn't valid C.

Sign up to request clarification or add additional context in comments.

Comments

3
#define ROW_CNT 8; 
#define COLUMN_CNT 24; 
#define FIRST_COLUMN 2; 

should be

#define ROW_CNT 8
#define COLUMN_CNT 24
#define FIRST_COLUMN 2

semicolons should not be used for #define

Comments

1

A pre-processor definition, such as ROW_CNT, replaces any instances of the identifier in your code with the value it's defined as being. Therefore once the pre-processor has expanded your macros, your code will look like:

unsigned int volume[8;][24;][2;];

As you can see, the semicolon is included after 8, 24 and 2, since that's how you defined ROW_CNT, COLUMN_COUNT and FIRST_COUNT to be, and that's obviously not valid C syntax.

Remove the semicolons from the end of your #defines and the code will compile.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.