Bing Hsu
Bing Hsu

Reputation: 722

C Macro Function Error

I defined such a macro function in c:

#define NUM_FROM_DENSE_MAT (PTR, II, JJ, RROW) ((PTR[JJ * RROW + II]))

And I called as following:

/*io.h:141*/ float num = NUM_FROM_DENSE_MAT(p_mat->p_val_host, i, j, p_mat->row);

Where p_mat->p_val_host is a float array, and all others are int number.

But when I complie it, I got the following error:

io.h(141): error: identifier "PTR" is undefined

io.h(141): error: identifier "II" is undefined

io.h(141): error: identifier "JJ" is undefined

io.h(141): error: identifier "RROW" is undefined

Should it not be translate to p_mat->p_val_host[j * p_mat->row + i]?

Upvotes: 0

Views: 135

Answers (1)

RichieHindle
RichieHindle

Reputation: 281805

Remove the space from the macro definition:

#define NUM_FROM_DENSE_MAT(PTR, II, JJ, RROW) ((PTR[JJ * RROW + II]))
                         ^^

Your code was defining a parameterless macro called NUM_FROM_DENSE_MAT.

Upvotes: 1

Related Questions