Padding bits

J

john

Many times I have seen padding bits being mentioned here. What is the
purpose of the padding bits?
 
V

Victor Bazarov

john said:
Many times I have seen padding bits being mentioned here. What is the
purpose of the padding bits?

I believe it's for making sure members are aligned according to the
hardware requirements. Well, I don't know exactly, actually, but it
seems reasonable enough. So, there...

V
 
A

Andrey Tarasevich

john said:
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.
 
J

john

Andrey said:
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".

And what is the purpose of these padding bits/bytes between members of a
struct?
 
S

Sjouke Burry

john said:
And what is the purpose of these padding bits/bytes between members of a
struct?
To make them align on a 4 or 8 byte boundary, so that a straight
memory fetch can be used for each variable in the struct.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top