1
votes

As stated at cppreference (emphasis mine):

The value of std::numeric_limits::digits is the number of digits in base-radix that can be represented by the type T without change. For integer types, this is the number of bits not counting the sign bit and the padding bits (if any). For floating-point types, this is the number of digits in the mantissa.

It is possible for an implementation to add padding bits to the fundamental types. Is there any implementation where any of these types are actually padded? Is this wording necessary to support all hardware or is this just the standard being paranoid?

1
Are you interested in integer or any fundamental types? std::nullptr_t consists entirely of padding bits, AFAIK. - Language Lawyer
Integer types are certainly more interesting, but std::nullptr_t is a valid point. - Mestkon
You might want to look up options, supported by some compilers, related to "packing" or "packing level". This can affect fundamental types separately from their natural alignment, not just compound/struct types. If the "packing level" is larger than their natural alignment, the organisation of an array of (say) 32 bit integers will be affected - natural alignment of 4, if packing level is 7, then each 32 bit integer in an array is placed on an 8-byte boundary (7 rounded to next multiple of 4). This means additional padding of that type. - Peter

1 Answers

1
votes

std::numeric_limits<bool>::digits returns 1, indicating bool is padded (typically 7 of 8 bits).