C++ pointer of specific bit size

bit-fields, c++, pointers, struct

Solution

In C++, the smallest addressable value must have a size of at least 1 byte. So No you cannot take address of an bit field with pointers.

C++03 Standard 9.6 Bit-fields: Para 3:

...The address-of operator& shall not be applied to a bit-field, so there are no pointers to bit-fields. ....

Problem

My question is about pointing to chunks of memory of an odd size. Let's say I have a `struct` declared like so: ``` typedef struct{ int32 val1 : 29; int32 val2 : 26; char val3; }MyStruct; ``` Let's assume declaring specific bit fields in the struct is desireable (why we'd use the bit fields is not the question). If I wanted to declare a pointer that points to one of those fields, I might try something like this: ``` MyStruct test; int32 *myPtr = &(test.val1); ``` Except that this produces the error "taking the address of a bit field is not allowed". Assuming that we would want to, is there a way to point to those fields in this way? I know that C++ will probably pad the fields to the next byte (which in this case would be 32 bits).

Original source