Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

type cast warnings

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

I have two warnings when I try to type cast. There probably not a big deal since I used the code from a book. Its when you use a static window procedure and type cast it into the class. The code from the book compiles fine. Is there something in the compiler settings?

SetWindowLong(hWnd, GWL_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));

warning C4311: 'type cast' : pointer truncation from 'LPVOID' to 'long'

//AND

(IApplication*)(GetWindowLong(hWnd, GWL_USERDATA));

warning C4312: 'type cast' : conversion from 'LONG' to Impulse::Core::IApplication *' of greater size


Share this post


Link to post
Share on other sites
Advertisement
A pointer may be bigger than a long, e.g. on a 64-bit platform. There's an option to disable that check in the project settings.

Share this post


Link to post
Share on other sites
I couldn't find anything. I don't know what it would say or where it would be. I am using vs2003. I did fix the first warning with PtrToUlong()

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can use #pragma's to disable these sort of warnings. I'd just encapsulate them in #ifdef _WIN32/#endif so you can keep them completely OS independant. 2 lines of code makes life much easier.

Share this post


Link to post
Share on other sites
*sigh*

(Solution Explorer)→(Project name)→(Right Click)→Properties→C/C++→General→Detect 64-bit Portability Issues→No.

Or just don't cast your pointers to LONG (size_t is a safer bet).

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!