#define 和 CUDA
为什么以下代码片段不适用于 CUDA(3.2 和 4.0)?
#define NUM_BLOCKS 16
// lots of code.
dim3 dimBlock(NUM_BLOCKS, NUM_BLOCKS);
但这,
dim3 dimBlock(16, 16);
是吗?
我不断收到错误:期望一个“)”
和错误:期望一个表达式
。我缺少什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你确定你没有写
(注意最后的分号)?
当错误分号存在时,我完全得到了您所描述的错误。
Are you certain you didn't write
(note the semicolon at the end)?
I get exactly the errors you described, when the erroneus semicolon is there.
这很奇怪。这可能是因为宏的常见问题。如果您知道,宏不尊重范围。可能在其他地方定义了相同的宏,但有所不同。
为什么不使用
const int
或enum
而不是宏?您知道吗:C++ - enum vs. const vs. #define ? ?
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
orenum
instead of macro?Do you know this: C++ - enum vs. const vs. #define ??
找出答案的一种方法是让编译器驱动程序在预处理阶段后停止,以便您可以看到生成的内容。这将向您显示预处理器替换的内容,从而为您提供搜索内容。
如果您使用 gcc,则该选项为 -E,对于 MSVC,该选项为 /E。
对于 nvcc 编译器驱动程序,典型的命令是
One way to find out is to get your compiler driver to stop after the preprocessing stage so that you can see what has been generated. This will show you what the preprocessor substituted and therefore gives you something to search for.
The option is -E if you are using gcc and /E for MSVC.
For the nvcc compiler driver a typical command would be