When 1 != 1
-
Here's the code:
enum EAxisType
{
AxisX = 0,
AxisY,
AxisZ
};struct AxisID
{
EAxisType axisType : 2; // X Y or Z
int axisIdx : 8; // multiple axes allowed
// ...
};vod Surprise()
{
AxisID axisID;
axisID.axisType = AxisZ;
assert(axisID.axisType == AxisZ); // fails! (VC6, VC8)
}Why? :cool: It took me a while to figure out, and I am not 100% sure what the standard says about this. Might not be reproducable on your compiler, or depend on a compiler option. axisIdx doesn't matter and can be omitted
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify!|Fold With Us! -
Here's the code:
enum EAxisType
{
AxisX = 0,
AxisY,
AxisZ
};struct AxisID
{
EAxisType axisType : 2; // X Y or Z
int axisIdx : 8; // multiple axes allowed
// ...
};vod Surprise()
{
AxisID axisID;
axisID.axisType = AxisZ;
assert(axisID.axisType == AxisZ); // fails! (VC6, VC8)
}Why? :cool: It took me a while to figure out, and I am not 100% sure what the standard says about this. Might not be reproducable on your compiler, or depend on a compiler option. axisIdx doesn't matter and can be omitted
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify!|Fold With Us!because the default type for the enum is signed, so one of the two bits is used for a sign, and AxisZ (which is 2) overflows the range (which is zero or one). Could be fixed by changing the 2 to a 3, or adding ": unsigned" to the end of the enum declaration (to specify the type of the enum). Out of curiosity, I'd like to know why you are using bit fields anyway. How little RAM does your target machine have, or how big is your data set?
Want robust software? Use the new Vista Kernel Transaction Manager[^]
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
because the default type for the enum is signed, so one of the two bits is used for a sign, and AxisZ (which is 2) overflows the range (which is zero or one). Could be fixed by changing the 2 to a 3, or adding ": unsigned" to the end of the enum declaration (to specify the type of the enum). Out of curiosity, I'd like to know why you are using bit fields anyway. How little RAM does your target machine have, or how big is your data set?
Want robust software? Use the new Vista Kernel Transaction Manager[^]
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Right - I had to debug the assembly to see it :doh: For Hysterical Raisins - AxisIDs are passed around as DWORDs, and used as array indices in some places, and I am not going to mess around with this (although it looks as if I could).
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify!|Fold With Us! -
Right - I had to debug the assembly to see it :doh: For Hysterical Raisins - AxisIDs are passed around as DWORDs, and used as array indices in some places, and I am not going to mess around with this (although it looks as if I could).
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify!|Fold With Us!peterchen wrote:
Right - I had to debug the assembly to see it
I admit I had to use the debugger to see the change, but once I saw it go to a negative number, I immediately suspected a signed/unsigned issue. Warren P.S. Great Addin article: http://www.codeproject.com/tools/vs2005addinmgr.asp[^] I had a trial version of an Add-in that expired (which wouldn't let me remove it easily) :-D
Want robust software? Use the new Vista Kernel Transaction Manager[^]
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
because the default type for the enum is signed, so one of the two bits is used for a sign, and AxisZ (which is 2) overflows the range (which is zero or one). Could be fixed by changing the 2 to a 3, or adding ": unsigned" to the end of the enum declaration (to specify the type of the enum). Out of curiosity, I'd like to know why you are using bit fields anyway. How little RAM does your target machine have, or how big is your data set?
Want robust software? Use the new Vista Kernel Transaction Manager[^]
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
-
peterchen wrote:
Right - I had to debug the assembly to see it
I admit I had to use the debugger to see the change, but once I saw it go to a negative number, I immediately suspected a signed/unsigned issue. Warren P.S. Great Addin article: http://www.codeproject.com/tools/vs2005addinmgr.asp[^] I had a trial version of an Add-in that expired (which wouldn't let me remove it easily) :-D
Want robust software? Use the new Vista Kernel Transaction Manager[^]
www.IconsReview.com[^] Huge list of stock icon collections (both free and commercial)
Warren Stevens wrote:
Great Addin article: http://www.codeproject.com/tools/vs2005addinmgr.asp\[^\] I had a trial version of an Add-in that expired (which wouldn't let me remove it easily)
Thanks! (It helps to know it's used :))
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify!|Fold With Us! -
Here's the code:
enum EAxisType
{
AxisX = 0,
AxisY,
AxisZ
};struct AxisID
{
EAxisType axisType : 2; // X Y or Z
int axisIdx : 8; // multiple axes allowed
// ...
};vod Surprise()
{
AxisID axisID;
axisID.axisType = AxisZ;
assert(axisID.axisType == AxisZ); // fails! (VC6, VC8)
}Why? :cool: It took me a while to figure out, and I am not 100% sure what the standard says about this. Might not be reproducable on your compiler, or depend on a compiler option. axisIdx doesn't matter and can be omitted
Developers, Developers, Developers, Developers, Developers, Developers, Velopers, Develprs, Developers!
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify!|Fold With Us!One more note: This
vod Surprise() { AxisID axisID; axisID.axisType = AxisZ; assert(axisID.axisType == AxisZ); // fails! (VC6, VC8) }
becomesvoid Surprise() { AxisID axisID; axisID.axisType = AxisZ; assert(axisID.axisType == AxisZ); // fails! (VC6, VC8) }
ROFLOLMFAO