D
DiAvOl
Hello everyone,
I read here and there that bit-field usage should be avoided because
it's not portable. My question is why it's not portable?
For example let's say I have a struct in my code with bit-fields like
the following:
struct bitfield_t {
unsigned int val1 : 1;
unsigned int val2 : 3;
unsigned int val3 : 2;
};
How can such a bit-field struct be used in a non portable way? (Can
you give me an example if possible)
In my understanding non-portable means that if you save a struct like
this in a binary form (in a file for example or send it over the
network) and then try to restore it on a platform with different
endianness or compiler it probably will be interpreted differently. Is
this the only case in which the usage of bit-fields is not portable?
Will source code which contains bit-fields like bitfield_t work
(execute) the same on different platforms (Without considering how the
bits are saved on each platform)?
Thanks for your time
I read here and there that bit-field usage should be avoided because
it's not portable. My question is why it's not portable?
For example let's say I have a struct in my code with bit-fields like
the following:
struct bitfield_t {
unsigned int val1 : 1;
unsigned int val2 : 3;
unsigned int val3 : 2;
};
How can such a bit-field struct be used in a non portable way? (Can
you give me an example if possible)
In my understanding non-portable means that if you save a struct like
this in a binary form (in a file for example or send it over the
network) and then try to restore it on a platform with different
endianness or compiler it probably will be interpreted differently. Is
this the only case in which the usage of bit-fields is not portable?
Will source code which contains bit-fields like bitfield_t work
(execute) the same on different platforms (Without considering how the
bits are saved on each platform)?
Thanks for your time