Set whole Data to a struct with BitFields
-
Hi all, I need to define a structure (its some spec frame-structure), so that I can assign data and retrieve-fields easily. So my definition is like below
struct MyDef
{
DWORD B1 : 8;
DWORD B2 : 8;
DWORD B3 : 8;
DWORD B4 : 8;
};(Note that, the whole struct contains 32 bits.) Now, I need a way to set some DWORD value to it directly. something like this
MyDef Def;
Def.data = 0xAABBCCDD;//This is the requirement. The 'data' needs to be defined in MyDef in such a way that this gets splits to the fields already defined(please note that, I need to keep the bit-fields so that I can set the fields as well.) Please help me.
-
Hi all, I need to define a structure (its some spec frame-structure), so that I can assign data and retrieve-fields easily. So my definition is like below
struct MyDef
{
DWORD B1 : 8;
DWORD B2 : 8;
DWORD B3 : 8;
DWORD B4 : 8;
};(Note that, the whole struct contains 32 bits.) Now, I need a way to set some DWORD value to it directly. something like this
MyDef Def;
Def.data = 0xAABBCCDD;//This is the requirement. The 'data' needs to be defined in MyDef in such a way that this gets splits to the fields already defined(please note that, I need to keep the bit-fields so that I can set the fields as well.) Please help me.
Without actually trying this out.... you should be able to take the pointer to the first element and load it with whatever data you want. Assuming your data matches the size of the structure, there should be no issue, be ware of data packing/memory alignment though. Read this before you get yourself into trouble.[^]
-
Hi all, I need to define a structure (its some spec frame-structure), so that I can assign data and retrieve-fields easily. So my definition is like below
struct MyDef
{
DWORD B1 : 8;
DWORD B2 : 8;
DWORD B3 : 8;
DWORD B4 : 8;
};(Note that, the whole struct contains 32 bits.) Now, I need a way to set some DWORD value to it directly. something like this
MyDef Def;
Def.data = 0xAABBCCDD;//This is the requirement. The 'data' needs to be defined in MyDef in such a way that this gets splits to the fields already defined(please note that, I need to keep the bit-fields so that I can set the fields as well.) Please help me.