Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Comparison of (int)DWORD

Comparison of (int)DWORD

Scheduled Pinned Locked Moved C / C++ / MFC
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikey_H
    wrote on last edited by
    #1

    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;
    }

    C P 2 Replies Last reply
    0
    • M Mikey_H

      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;
      }

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      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++

      M 1 Reply Last reply
      0
      • C Cedric Moonen

        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++

        M Offline
        M Offline
        Mikey_H
        wrote on last edited by
        #3

        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?

        C D 2 Replies Last reply
        0
        • M Mikey_H

          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?

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          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++

          M 1 Reply Last reply
          0
          • C Cedric Moonen

            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++

            M Offline
            M Offline
            Mikey_H
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • M Mikey_H

              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;
              }

              P Offline
              P Offline
              Perry Holman
              wrote on last edited by
              #6

              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!

              1 Reply Last reply
              0
              • M Mikey_H

                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

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                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++

                M 1 Reply Last reply
                0
                • C Cedric Moonen

                  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++

                  M Offline
                  M Offline
                  Mikey_H
                  wrote on last edited by
                  #8

                  Function should return true if all 3 values do not equal 0

                  C 1 Reply Last reply
                  0
                  • M Mikey_H

                    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?

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • M Mikey_H

                      Function should return true if all 3 values do not equal 0

                      C Offline
                      C Offline
                      Cedric Moonen
                      wrote on last edited by
                      #10

                      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++

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups