Archived

This topic is now archived and is closed to further replies.

d000hg

Stupid millions of warnings

Recommended Posts

My structures commonly use WORDs, but in any loops using ints as indices or whatever you get millions of warning about signed/unsigned mismatches and setting shorts to ints. Frequently it''s not possible to choose index types or whatever that are compatible with every var type being used in the loop. especially since:
WORD x=4;
WORD y=3;
if((x-1)==y)
{
.
.
.
}
 
Treats x-1 as an int due to stupid promotion. Also comparing WORDs to 0 seems problematic as this is treated as an int. I could disable the warnings, but there could easily arise a bug where I do forget the limits of vars and try to assign outside range - here I''d like to be warned so I can check. But 100 warnings that I can''t fix is a lot to wade through to find the ''real'' one.
Read about my game, project #1 NEW (13th August): A new screenshot is up, plus diaries for week #3
John 3:16

Share this post


Link to post
Share on other sites
You can fix it. Just use a cast, it should shut the compiler up. You should use C++-style casts, but they are quite long to write for something trivial like this. C-style casts should do the job. I know that''s what I used when I switched to VC++.net.

Cédric

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Non standard types will do that to you. Have you thought about using a unsigned short and C style type casting to WORD if necessary? That''s of cource assuming that an unsigned short will excaped an int promotion, or at least be promoted to an unsigned int.

Your macros should still work on the unsigned short (HIBYTE, LOBYTE). If not, use a C-Style Type cast.

Heck, use a C-Style type cast to change the WORD to an unsigned short when need be:

if((unsigned short)x - 1) == (unsigned short) y) do something;

These are simply ideas I would try, I don''t know if they would work without firing up my compiler.

Share this post


Link to post
Share on other sites
It just seems dumb having to litter my code with billions of casts. Isn''t a WORD typdeffed to be a short unsigned, making them identical?



Read about my game, project #1
NEW (13th August): A new screenshot is up, plus diaries for week #3


John 3:16

Share this post


Link to post
Share on other sites
just don''t code like this right from the beginning...

i don''t have any warnings with using my own types, as i know wich one is used when. nearly no casts needed. if you know what you do you know what you need, and you use this. all those castings wich vc has to do for you can lead to errors, and can as well slow down..


WORD x=4;WORD y=3;if((x-1)==y){...}


say this.

WORD is unsigned? if so, if x == 0, it could be a wrong error comming..

bether handle it like this:

if(x==y+1) {
}

there shouldn''t be a warning anymore..

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
I just disable the warning when I get them like that ( ones that don''t matter ), or at least select a less sensitive warning setting...



Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
To disable a specific warning you can use this pragma :

#pragma warning(disable:4800) // where 4800 is the warning code you want to disable...

__________________________



Bruno Wieckowski
Lead Programmer
Exood4 Studios


[edited by - brunow on August 18, 2002 7:26:32 AM]

Share this post


Link to post
Share on other sites