bit field

hi,

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


thanks!
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.
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???
I have no idea what you just said.

What problem are you experiencing?
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???

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-
?
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;
}
Topic archived. No new replies allowed.