c 程序 static_assert() char bit=16
这段代码中的 CHAR_BIT==16
是什么意思?它无法编译,我无法弄清楚原因以及 put 中的内容,以便代码可以编译?
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
static_assert(CHAR_BIT==16,"16 bit falsely assumed");
int main()
{
puts("hello world this");
return 0;
}
What is CHAR_BIT==16
means in this code? It doesn't compile, I can not figure out the reason and what will be in puts so code will compile?
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
static_assert(CHAR_BIT==16,"16 bit falsely assumed");
int main()
{
puts("hello world this");
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
CHAR_BIT
是在limits.h
中定义的宏。它提到了char
中的位数。大多数系统使用 8 位,但也有更少(7 位)或更多的体系结构。在您的代码中,断言正在检查,如果系统对
char
使用 16 位,则只有代码会编译。注意:根据您的编译器版本和支持,您可能需要使用
_Static_assert
。CHAR_BIT
is a Macro defined inlimits.h
. It mentions the number of bits in achar
. Most systems use 8 bits, but there are architectures with less (7 bits) or more.In your code, the assert is checking, if the system is using 16 bits for a
char
, then only the code will compile.Note: Based on your compiler version and support, you may need to use
_Static_assert
instead.CHAR_BIT
在
中定义。您需要包含它才能编译代码。CHAR_BIT
is defined in<limits.h>
. You need to include it for your code to compile.