Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C error: missing whitespace after the macro name

I wrote the following macro:

#define m[a,b] m.values[m.rows*(a)+(b)]

However gcc gives me this error:

error: missing whitespace after the macro name

What is wrong and how do I fix it?

like image 580
Hannesh Avatar asked Dec 10 '22 06:12

Hannesh


2 Answers

You cannot use [ and ] as delimiters for macro arguments; you must use ( and ). Try this:

#define m(a,b) m.values[m.rows*(a)+(b)]

But note that defining the name of a macro as the name of an existing variable may be confusing. You should avoid shadowing names like this.

like image 119
cdhowie Avatar answered Dec 24 '22 09:12

cdhowie


I'm not familiar with any C preprocessor syntax that uses square brackets. Change

  #define m[a,b] m.values[m.rows*(a)+(b)]

to

  #define m(a,b) m.values[m.rows*(a)+(b)]

And it should work.

like image 27
Doug T. Avatar answered Dec 24 '22 10:12

Doug T.