barak manos barak manos - 4 years ago 189
C Question

How does the language standard define uint8_t when CHAR_BIT > 8?

I don't have any platform with

at hand.

So I changed the related preprocessor definitions in file

#define CHAR_BIT 16 /* number of bits in a char */
#define SCHAR_MIN (-32768) /* minimum signed char value */
#define SCHAR_MAX 32767 /* maximum signed char value */
#define UCHAR_MAX 0xffff /* maximum unsigned char value */

Then, when including file
, I'd expect to see that
was no longer a viable type.

Yet it is.

How does the language standard settle this?

Answer Source

The file limits.h is not a configuration file for your compiler; it is a mechanism via which the implementation provides information to you. Your compiler knows that char has 8 bits and that uint8_t is unsigned char; it doesn't need to read the limits.h file to find that out.

If you want a car analogy, hammering a nail through your fuel gauge won't prevent you from running the tank dry.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download