Jump to content
  • Advertisement
Sign in to follow this  
graveyard filla

is it possible? ( warnings with VS.net 2003)

This topic is 4974 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, does anyone know if its possible to turn on warnings about explicit casting which could hurt the value of something in VS.net 2003? basically, something like this: int x = 50; unsigned char y = (unsigned char)x; i want a warning, even though i have the () cast their. thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Yes, but you might have to get rid of the cast.

Compiler Warning (level 4) C4242

'identifier' : conversion from 'type1' to 'type2', possible loss of data

You can set your warning level to 4, or explicitly turn on the warning using the "warning" pragma. Go here.

Share this post


Link to post
Share on other sites
hi,

that warning doesnt seem to do what i want it to do. it gives me warnings for some casting but not for the explicit cast (e.g.) int a = (int)some_char.

thanks for any more help.

Share this post


Link to post
Share on other sites
out of intrest, why do you want to?
The whole point of an explicate cast is that you are saying to the compiler "dont worry, I know what I'm doing, trust me! I'm a programmer!" (ofcourse, this is often followed by the screams of the damned as your program crashes and opens a gateway to hell..)

Share this post


Link to post
Share on other sites
yeah, i guess that was a bad example. switch up int with char [grin].

also, the reason i want to do this is kind of hard to explain but, im making a multiplayer RPG and i just switched all my data types that i use to send over the wire (Uint8,Uint16,etc..) to typedefs. before i had them hardcoded. i wanted them to be typedefs so later if i want to change the max amount of players or how i send positions or something i only have to change the typedef.

anyway, basically when i write to a packet i do something like packet.write((Player_NetID)some_player->Get_NetID()). anyway, when i switched from it saying "Uint8" to "Player_NetID", i just wanted to turn on a warning so i could make sure i didnt screw up anywhere and forget to change it in some place.

also, some_player->Get_NetID() actually returns an integer, but Player_NetID is typedef'd to be an unsigned char. the reason for this is because Get_NetID() is actually from one of Player's parent classes, which is also the parent of NPC, etc. when sending NPC and other ID's, i send an integer, but when sending players, i will never have more then 256 players, so i send it as a byte (and for players i only take from the "ID pool" values less then 256). anyway, this is why i cast everywhere so when i look at it i know for sure what im looking at. slightly OT: is it possible to over-ride the return value of a parents function from a child? im guessing not.. maybe a way to fake it?

Share this post


Link to post
Share on other sites
so i guess the answer is "No"? guess ill just have to trust myself.. or, more likely, pull my hair out when i try running the game and random bugs start popping up [grin].

Share this post


Link to post
Share on other sites
Quote:
Original post by graveyard filla
so i guess the answer is "No"? guess ill just have to trust myself.. or, more likely, pull my hair out when i try running the game and random bugs start popping up [grin].


I have an idea of something you can try - but I do not have my computer, so I cannot test it or give a complete solution. There is a compiler pragma directive that you can use to change some warnings. All you have to do is get the linker warning number and use that.

Here is the MSDN refrence I am talking about. Hope it helps!

- Drew

Share this post


Link to post
Share on other sites
Quote:
Original post by graveyard filla
...anyway, basically when i write to a packet i do something like packet.write((Player_NetID)some_player->Get_NetID()). anyway, when i switched from it saying "Uint8" to "Player_NetID", i just wanted to turn on a warning so i could make sure i didnt screw up anywhere and forget to change it in some place.

also, some_player->Get_NetID() actually returns an integer, but Player_NetID is typedef'd to be an unsigned char.


Maybe make Get_NetID() return a Player_NetID instead of an int? That would make more sense to me anyway. The purpose of the type Player_NetID is to hold a player net ID, so any place you are going to have one of those just go ahead and use that type. Then if you need to change it in the future it will change everywhere. It seems like it's a bad idea to store it anywhere as an int if you aren't going to make it an int everywhere.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!