Jump to content
  • Advertisement
Sign in to follow this  

how to c++ cast from int so ushort

This topic is 3945 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

the int will always be positive and within the range of possible values for a short. external library has poor design. int x = getWidth(); unsigned short xx = x; //how to cast this in c++

Share this post


Link to post
Share on other sites
Advertisement
The reinterpret_cast is bad for a lot of reasons. Number one of which is that it won't work properly in a number of situations. For example, using it on a big-endian machine will cause it to reinterpret the wrong set of bytes. There's no reason to get cute when doing a simple cast.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
The reinterpret_cast is bad for a lot of reasons. Number one of which is that it won't work properly in a number of situations. For example, using it on a big-endian machine will cause it to reinterpret the wrong set of bytes. There's no reason to get cute when doing a simple cast.


I completely agree. I was indeed trying to be cute, and in no way meant it to be taken seriously.

Share this post


Link to post
Share on other sites
Why are you copying it to an unsigned short? What do you gain? The fact that it is "always" positive and that it fits in a short are not really very good reasons.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!