john wrote:
Many times I have seen padding bits being mentioned here. What is the
purpose of the padding bits?
You might need to give more context.
Most often the term "padding bits" refer to the bits in the object
representation of some scalar type, which do not participate in forming
the value of that type. These bits might be simply unused. Or they may
serve some internal household purpose, like acting as parity bits,
error-correction bits etc. For example, on some system an object of type
'double' might occupy, say, 64 bits, buy only 60 might actually be used
to represent the value. The remaining 4 bits would become padding bits
in this case. They might serve some special purpose. It is quite
possible that they might be set by the implementation/hardware in some
specific fashion and setting them manually (like trying to zero a
'double' object with 'memset') might easily lead to undefined behavior.
Another area when the term "padding" is often mentioned is the padding
between the members of the structure. Although these are usually
referred to as "padding bytes", not "padding bits".
Unused bits in the allocation unit reserved for bit fields probably fall
somewhere in between.
--
Best regards,
Andrey Tarasevich