当编译器未提供 uint8_t 时,什么是更好的替代方案?
我正在使用 nvcc 编译 CUDA 内核。不幸的是,nvcc 似乎不支持 uint8_t
,尽管它确实支持 int8_t
(!)。出于可移植性、可读性和理智的原因,我宁愿不使用 unsigned char
。还有其他好的选择吗?
为了防止任何可能的误解,这里有一些细节。
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Mon_Jun__7_18:56:31_PDT_2010
Cuda compilation tools, release 3.1, V0.2.1221
包含的代码
int8_t test = 0;
很好,但是包含的代码
uint8_t test = 0;
会引发错误消息,例如
test.cu(8): error: identifier "uint8_t" is undefined
I'm using nvcc to compile a CUDA kernel. Unfortunately, nvcc doesn't seem to support uint8_t
, although it does support int8_t
(!). I'd just as soon not use unsigned char
, for portability, readability, and sanity reasons. Is there another good alternative?
Just to forestall any possible misunderstanding, here are some details.
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2010 NVIDIA Corporation
Built on Mon_Jun__7_18:56:31_PDT_2010
Cuda compilation tools, release 3.1, V0.2.1221
Code containing
int8_t test = 0;
is fine, but code containing
uint8_t test = 0;
throws an error message like
test.cu(8): error: identifier "uint8_t" is undefined
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
C99 整数类型不是“由编译器定义”——它们是在
中定义的。尝试:
C99 integer types are not "defined by the compiler" - they are defined in
<stdint.h>
.Try:
这与 Mac OS X 使用的没有什么不同:
您对
unsigned char
的可移植性有何担忧?如果担心char
可能不代表 8 位存储,那么您可以包含一个静态断言,其内容如下:当违反假设时,这将导致编译出错。
This is no different from what Mac OS X uses:
What is your concern about the portability of
unsigned char
? If the concern is that achar
might not represent 8 bits of storage, then you can include a static assertion along the lines of:This will cause compilation to error out when the assumption is violated.
这似乎可以用 nvcc 编译得很好:
This seems to compile just fine with
nvcc
: