Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define and CUDA

Why does the following snippet not work with CUDA (both 3.2 and 4.0)?

#define NUM_BLOCKS 16

// lots of code.

dim3 dimBlock(NUM_BLOCKS, NUM_BLOCKS);

but this,

dim3 dimBlock(16, 16);

does?

I keep getting a error : expected a ")" and error : expected an expression. What am I missing?

like image 218
Kristian D'Amato Avatar asked Sep 09 '26 02:09

Kristian D'Amato


2 Answers

Are you certain you didn't write

#define NUM_BLOCKS 16;

(note the semicolon at the end)?

I get exactly the errors you described, when the erroneus semicolon is there.

like image 87
CygnusX1 Avatar answered Sep 10 '26 14:09

CygnusX1


That is strange. It may be because of the usual problem with macros. If you know, macros don't respect scope. It may be that the same macro is defined elsewhere, but differently.

Why don't you use const int or enum instead of macro?

Do you know this: C++ - enum vs. const vs. #define ??

like image 35
Nawaz Avatar answered Sep 10 '26 15:09

Nawaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!