By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,992 Members | 934 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,992 IT Pros & Developers. It's quick & easy.

Padding bits

P: n/a
Many times I have seen padding bits being mentioned here. What is the
purpose of the padding bits?
Nov 2 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
john wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 2 '07 #2

P: n/a
john wrote:
Many times I have seen padding bits being mentioned here. What is the
purpose of the padding bits?
Bits or bytes?

--
Ian Collins.
Nov 2 '07 #3

P: n/a
Ian Collins wrote:
john wrote:
>Many times I have seen padding bits being mentioned here. What is the
purpose of the padding bits?

Bits or bytes?
Don't the latter consist of the former? :-)

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 2 '07 #4

P: n/a
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
Nov 2 '07 #5

P: n/a
Andrey Tarasevich wrote:
>
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?
Nov 2 '07 #6

P: n/a
john wrote:
Andrey Tarasevich wrote:
>>
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?
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.
Nov 2 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.