Search code examples
cposix

Why isn't there an INT_BIT?


Why are there _BIT macros in limits.h for CHAR_BIT, LONG_BIT, WORD_BIT? Why doesn't it define an INT_BIT?

Is there a reason why these macros are defined for other types, but not for int? Are these deprecated (out of use) with sizeof?

I see these are defined by POSIX for limits.h


Solution

  • It looks like WORD_BIT is what you want to be INT_BIT, from the document you link to:

    {WORD_BIT} Number of bits in an object of type int.

    Note that CX means this is an extension to standard C.

    The C99 rationale document tells us the committee saw little reason for anything besides CHAR_BIT:

    The macro CHAR_BIT makes available the number of bits in a char object. The C89 Committee saw little utility in adding such macros for other data types.

    likely because CHAR_BIT*sizeof(type) does what you need.