bit field

Apr 21, 2009 at 7:56am
hi,

i would like to ask about bits fields is it a standard??
and why not is it not portable???


thanks!
Apr 21, 2009 at 8:40am
The handling of bit fields is standardised. There are shift and logical operators that support it.

Different computer architectures may interpret given bit patterns differently.

For example, an int is the size of the architecture's word and may vary.
Apr 21, 2009 at 8:45am
i am understanding what are you saying.
my problem yet is portability and many expert say that isn't portable???
i have verified the BYTE_ORDER by also they say no!!
i don't understand why???
Apr 21, 2009 at 10:08am
I have no idea what you just said.

What problem are you experiencing?
Apr 21, 2009 at 10:25am
so,

i am thinking about portability, right!
many expert said that bit field are not portable because of no strandardisation of bit field: this that right or false???

Apr 21, 2009 at 12:07pm
Are you talking about custom-sized data types:
1
2
3
4
5
struct BitField
{
    bool onebit: 1;
    unsigned number: 31;
};

Or about STL
http://www.cplusplus.com/reference/stl/bitset/
http://www.cplusplus.com/reference/stl/vector/ -bool specialization-
?
May 11, 2009 at 11:07pm
At least one reason bit fields are not portable is because the orders are reversed on big endian and little endian machines.


+-------------------------------+
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
+-------------------------------+
| a | b |
+-------------------------------+


Big endian:
1
2
3
4
5
struct foo
{
    unsigned char a: 5;
    unsigned char b: 3;
};


Little Endian:
1
2
3
4
5
struct foo
{
    unsigned char b: 3;
    unsigned char a: 5;
}
May 11, 2009 at 11:26pm
Topic archived. No new replies allowed.