Sign in to follow this  
renman29

Ridiculous DWORD error (SOLVED - thanks)

Recommended Posts

DWORD g_num = 0; g_num--; if (g_num<0) g_num=5; PRINT("gnum = ",g_num); OUTPUT!!!: gnum = -1 Visual Studio 2005 glitch? I can't understand why this doesn't work... Update: DWORD g_num = 0; g_num--; if (g_num<0) g_num=5; if (g_num==-1) g_num=5 PRINT("gnum = ",g_num); OUTPUT: gnum = 5 What the heck is going on here?????????? Last time I checked, -1 is less than 0..... [Edited by - renman29 on April 7, 2007 8:16:34 AM]

Share this post


Link to post
Share on other sites
A good idea - in this circumstance I need a DWORD var - so what I actually ended up doing was something like this:

if (g_num<direction_increment)
g_num=MY_MAX-(direction_increment-g_num)+direction_increment;
gnum+=direction_increment;
if (g_num>MY_MAX) g_num=(g_num-MY_MAX);



Which is basically this sort of anticipation-logic:
if (gnum==0) gnum=5+1;
gnum--; //gnum becomes 5

I can't believe I didn't realize DWORD's unsigned.. I guess what threw me off was the fact that my PRINT function was still saying -1.
I'll stick to int's as much as possible. Thanks. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by renman29
I guess what threw me off was the fact that my PRINT function was still saying -1.


Then use a better one. (In particular, assuming C++, don't wrap printf-type stuff, because it's not typesafe. Instead, work with iostreams.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this