tags:

views:

133

answers:

5

I have to represent a 16 byte field as part of a data structure:

struct Data_Entry
{
    uint8   CUI_Type;
    uint8   CUI_Size;
    uint16  Src_Refresh_Period;
    uint16  Src_Buffer_Size;
    uint16  Src_CUI_Offset;
    uint32  Src_BCW_Address;
    uint32  Src_Previous_Timestamp;
    /* The field below should be a 16 byte field */
    uint32      Data;

};

How would I represent the "Data" field as a 16 byte field instead of the 4 byte field it currently is?

Thanks,

Bobby

+8  A: 

Use an array:

struct Data_Entry
{
    uint8   CUI_Type;
    uint8   CUI_Size;
    uint16  Src_Refresh_Period;
    uint16  Src_Buffer_Size;
    uint16  Src_CUI_Offset;
    uint32  Src_BCW_Address;
    uint32  Src_Previous_Timestamp;
    /* The field below should be a 16 byte field */
    uint32  Data[4];

};
kgiannakakis
+8  A: 

Anything wrong with uint8 Data[16];?

Chris
+1  A: 

You could also use boost::bitset<128>.

andand
Are you sure that works inside C compatible structs?
Joshua
@Joshua: I'm pretty sure it won't, but the question is tagged C++, not C.
andand
+4  A: 

I have a hard time to believe you want this 16byte field to be a scalar integer. In the odd event that int16B is what you want (for a fotonic enumerator application, observing the universe), you need to define it as a class, make appropriate storage (see below), overload every arithmetic operators, to make any good use of it.

If you want a set of 16 bytes under the same name, to which arithmetic wont be applied, use

uint8 Data[16];
jpinto3912
+2  A: 

Try one these:
uint8 Data[16];
or
uint16 Data[8];
or
uint32 Data[4];
or
uint64 Data[2]; // uint64 may not be available on all platforms

Or you could use std::vector instead of an array for the above.

Thomas Matthews