Bit fields, get that type-spec right [modified]
-
Just found this one:
typedef unsigned char byte;
typedef unsigned int uint;
#pragma CKPRAGMA_PACK_PUSH(1)typedef struct SkGuidTime {
short year; /* 16 */ // -32768 - +32,767
byte month : 4; // 1 - 12
byte day : 5; // 1 - 31, Day of Month
//.................
byte hour : 5; // 0 - 23
byte min : 6; // 0 - 59
byte sec : 6; // 0 - 59
//.................
byte res : 6; // 0 - 63
} SkGuidTime; /* 48 */ // 6 bytes#pragma CKPRAGMA_PACK_POP
This is being used as part of a function that generates a GUID. After a SkGuidTime tm is filled it is memcpy'd into the GUID: memcpy((byte*)&g.Data3, &tm, 6); It was noticed that the time section of the GUID wasn't changing across seconds, only minutes. ... unfortunately the structure, although compiles without error or warning, is actually 8 bytes. Each element gets it's own byte. Changing the type from byte to ushort or larger fixes things.
...cmk Save the whales - collect the whole set
-
Just found this one:
typedef unsigned char byte;
typedef unsigned int uint;
#pragma CKPRAGMA_PACK_PUSH(1)typedef struct SkGuidTime {
short year; /* 16 */ // -32768 - +32,767
byte month : 4; // 1 - 12
byte day : 5; // 1 - 31, Day of Month
//.................
byte hour : 5; // 0 - 23
byte min : 6; // 0 - 59
byte sec : 6; // 0 - 59
//.................
byte res : 6; // 0 - 63
} SkGuidTime; /* 48 */ // 6 bytes#pragma CKPRAGMA_PACK_POP
This is being used as part of a function that generates a GUID. After a SkGuidTime tm is filled it is memcpy'd into the GUID: memcpy((byte*)&g.Data3, &tm, 6); It was noticed that the time section of the GUID wasn't changing across seconds, only minutes. ... unfortunately the structure, although compiles without error or warning, is actually 8 bytes. Each element gets it's own byte. Changing the type from byte to ushort or larger fixes things.
...cmk Save the whales - collect the whole set
The bit field specifiers aren't ignored if it can fit on byte's length : byte month : 4; // 1 - 12 byte day : 4; // 1 - 16 This will fits in a byte ! To be sure everything to be in your uint, always stuff things like you done with 'res' to fill everything... Kochise
In Code we trust !