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;
}
CodePudding user response:
CHAR_BIT is a Macro defined in limits.h. It mentions the number of bits in a char. 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.
CodePudding user response:
CHAR_BIT is defined in <limits.h>. You need to include it for your code to compile.
