V
vippstar
Hey comp.lang.c
I'm somewhat confused with bit padding.
I tried searching the FAQ, but there isn't a search feature, so I used
google and the search query: site:c-faq.com padding.
I did not find anything relevant to bit padding, only byte padding for
structs, which more or less I understand.
All sections are from n1256
6.2.6.1 p4 says all objects except bit-fields consist of n * CHAR_BIT
bits, where n is sizeof object.
So if an int has padding bits, they are multiples of CHAR_BIT? Is
there a way to find which bits are the padding bits?
Padding bits can only be at the start/end of the object
representation, or anywhere? What happends if I access those padding
bits, by casting the object to (unsigned char *)? What happends if I
change the value of these padding bits?
6.2.6.1 p5 says the object representation does not have to represent
the value of the object type. I think I understand this, for example
with offset:segment pointers, where they could be mapped to the same
area, but have different values? If I understand correctly, == takes
care of this.
In sort, == compares values and memcmp() compares object
representations, right?
However, 6.2.6.2 note 43 says that x == y does not necessarily imply
that x and y have the same value.
I don't understand this, in my opinion contradicts the previous
paragraphs, does it not?
Why would an implementation want padding bits in any object type? Why
cannot these bits be used to increase the value range?
Why does the standard explicity mention that the byte that getchar() &
family functions read is returned casted to (unsigned char)? I think
it has something to do with 'unsigned char' being the only type that
doesn't have padding bits, but I'm not sure how/why that matters.
Lastly, can the bitshift operators manipulate the padding bits?
For example: int i = x; i <<= y;
All replies much appreciated.
I'm somewhat confused with bit padding.
I tried searching the FAQ, but there isn't a search feature, so I used
google and the search query: site:c-faq.com padding.
I did not find anything relevant to bit padding, only byte padding for
structs, which more or less I understand.
All sections are from n1256
6.2.6.1 p4 says all objects except bit-fields consist of n * CHAR_BIT
bits, where n is sizeof object.
So if an int has padding bits, they are multiples of CHAR_BIT? Is
there a way to find which bits are the padding bits?
Padding bits can only be at the start/end of the object
representation, or anywhere? What happends if I access those padding
bits, by casting the object to (unsigned char *)? What happends if I
change the value of these padding bits?
6.2.6.1 p5 says the object representation does not have to represent
the value of the object type. I think I understand this, for example
with offset:segment pointers, where they could be mapped to the same
area, but have different values? If I understand correctly, == takes
care of this.
In sort, == compares values and memcmp() compares object
representations, right?
However, 6.2.6.2 note 43 says that x == y does not necessarily imply
that x and y have the same value.
I don't understand this, in my opinion contradicts the previous
paragraphs, does it not?
Why would an implementation want padding bits in any object type? Why
cannot these bits be used to increase the value range?
Why does the standard explicity mention that the byte that getchar() &
family functions read is returned casted to (unsigned char)? I think
it has something to do with 'unsigned char' being the only type that
doesn't have padding bits, but I'm not sure how/why that matters.
Lastly, can the bitshift operators manipulate the padding bits?
For example: int i = x; i <<= y;
All replies much appreciated.