Comparison of (int)DWORD
-
Just wanted to check whether the code here in VerifyMaterial() is correct, it works, but as I learned from my last post that doesn't necessarily mean it is correct. I searched google for information but couldn't find anything specific, however any info I found seemed to be against a cast from DWORD to int.
BasicMaterial::BasicMaterial()
{
Ambient = NULL; // DWORD
Diffuse = NULL; // DWORD
Specular = NULL; // DWORD
}BOOL BasicMaterial::VerifyMaterial()
{
if (!(int)Ambient || !(int)Diffuse || !(int)Specular)
return false;
return true;
} -
Just wanted to check whether the code here in VerifyMaterial() is correct, it works, but as I learned from my last post that doesn't necessarily mean it is correct. I searched google for information but couldn't find anything specific, however any info I found seemed to be against a cast from DWORD to int.
BasicMaterial::BasicMaterial()
{
Ambient = NULL; // DWORD
Diffuse = NULL; // DWORD
Specular = NULL; // DWORD
}BOOL BasicMaterial::VerifyMaterial()
{
if (!(int)Ambient || !(int)Diffuse || !(int)Specular)
return false;
return true;
}Mikey_H wrote:
Just wanted to check whether the code here in VerifyMaterial() is correct
To be able to verify that, we need to know what you are trying to do... Anyway, the cast is not necessary here because a DWORD is an unsigned long. Thus checking if it is null doesn't require you to cast it to an int.
Cédric Moonen Software developer
Charting control [v2.0 - Updated] OpenGL game tutorial in C++ -
Mikey_H wrote:
Just wanted to check whether the code here in VerifyMaterial() is correct
To be able to verify that, we need to know what you are trying to do... Anyway, the cast is not necessary here because a DWORD is an unsigned long. Thus checking if it is null doesn't require you to cast it to an int.
Cédric Moonen Software developer
Charting control [v2.0 - Updated] OpenGL game tutorial in C++I want to check to see if the DWORDs have been set from an outside class. I had originally tried it without the cast, but that did not work. typedef DWORD D3DCOLOR; It is actually a D3DCOLOR but I assume the same rules apply?
-
I want to check to see if the DWORDs have been set from an outside class. I had originally tried it without the cast, but that did not work. typedef DWORD D3DCOLOR; It is actually a D3DCOLOR but I assume the same rules apply?
Mikey_H wrote:
I want to check to see if the DWORDs have been set from an outside class.
And what if they are set as 0 ? The only thing you can verify is check if they are different than 0.
Mikey_H wrote:
but that did not work.
Which means what exactly ? Anyway, if I have to check for if a value is different than zero, I use this notation:
if (myValue!=0)
, which is a bit clearer (just a matter of taste).Cédric Moonen Software developer
Charting control [v2.0 - Updated] OpenGL game tutorial in C++ -
Mikey_H wrote:
I want to check to see if the DWORDs have been set from an outside class.
And what if they are set as 0 ? The only thing you can verify is check if they are different than 0.
Mikey_H wrote:
but that did not work.
Which means what exactly ? Anyway, if I have to check for if a value is different than zero, I use this notation:
if (myValue!=0)
, which is a bit clearer (just a matter of taste).Cédric Moonen Software developer
Charting control [v2.0 - Updated] OpenGL game tutorial in C++I've tried again without the cast
if (!Ambient || !Diffuse || !Specular)
return false;which is working, I obviously didn't have it set up how I thought I did at first. Checking to make sure value is not 0 is fine, I just want to see if it has been "attempted" to be set, the variables will hold color values so they should not be 0 once set (I think). Thank you for your help Cedric
modified on Tuesday, April 21, 2009 1:23 PM
-
Just wanted to check whether the code here in VerifyMaterial() is correct, it works, but as I learned from my last post that doesn't necessarily mean it is correct. I searched google for information but couldn't find anything specific, however any info I found seemed to be against a cast from DWORD to int.
BasicMaterial::BasicMaterial()
{
Ambient = NULL; // DWORD
Diffuse = NULL; // DWORD
Specular = NULL; // DWORD
}BOOL BasicMaterial::VerifyMaterial()
{
if (!(int)Ambient || !(int)Diffuse || !(int)Specular)
return false;
return true;
}Basically, it's a bad code sytle to assign NULL to a DWORD variable. i think you should initialize them with 0 and later compare/verify them as below: if (Ambient == 0 || Diffuse == 0 || Specular == 0) { return false; }
Welcome to www.softwaretree.net! You can find many excellent audio/video converter tools there!
-
I've tried again without the cast
if (!Ambient || !Diffuse || !Specular)
return false;which is working, I obviously didn't have it set up how I thought I did at first. Checking to make sure value is not 0 is fine, I just want to see if it has been "attempted" to be set, the variables will hold color values so they should not be 0 once set (I think). Thank you for your help Cedric
modified on Tuesday, April 21, 2009 1:23 PM
By the way, your code returns false if one of the values is different than 0, is that what you want ? I would guess you want the opposite no ? Also, with numerical values, it is a bit clearer to consider them as numerical values, not boolean. Logically, it doesn't make any difference but it makes the code a bit more understandable (you want to check that the value is different than 0).
Cédric Moonen Software developer
Charting control [v2.0 - Updated] OpenGL game tutorial in C++ -
By the way, your code returns false if one of the values is different than 0, is that what you want ? I would guess you want the opposite no ? Also, with numerical values, it is a bit clearer to consider them as numerical values, not boolean. Logically, it doesn't make any difference but it makes the code a bit more understandable (you want to check that the value is different than 0).
Cédric Moonen Software developer
Charting control [v2.0 - Updated] OpenGL game tutorial in C++ -
I want to check to see if the DWORDs have been set from an outside class. I had originally tried it without the cast, but that did not work. typedef DWORD D3DCOLOR; It is actually a D3DCOLOR but I assume the same rules apply?
Mikey_H wrote:
I want to check to see if the DWORDs have been set from an outside class.
Are they public or private to the
BasicMaterial
class?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Yes you're right that's what it does. It's the end of the day here, so my brain has been turned off a couple of hours ago ;P
Cédric Moonen Software developer
Charting control [v2.0 - Updated] OpenGL game tutorial in C++