Sign in to follow this  

Unity warning C4312: /Wp64 switch of any use?

Recommended Posts

After reading up on this for some time, and getting many threads like this one: It seems like the "detect portability issues" switch in VS2005/VS2003 is a ridiculous joke. Even if you make your code "portable", by changing your typecasts: eg: long to LONG_PTR int to INT_PTR ...the warnings persist, when compiling for WIN32. It's silly that even something like this gets a warning: long id = 0; SetWindowLongPtr(hwndparent, GWLP_ID, (std::size_t)(id)); ...when in practice, it would compile fine under WIN64. Thoughts? Is there a way to create code that is both portable between 32/64 AND can satisfy the compiler with the switch enabled? Or am I just wrong about the whole thing? [Edited by - Verg on May 6, 2007 1:43:22 PM]

Share this post

Link to post
Share on other sites
Platform specific API might not be portable.

This may seem strange, but HWND in your case doesn't need to be. Platform API is provided for each platform independantly, and only needs to be "portable" for its own purposes.

What works in practice doesn't imply what is correct at language level. In practice, code that was only written for 32-bits may work flawlesly in 64-bit environment.

Also: HWND is either a pointer to struct or void*, and size_t is unsigned int.

There's no chance this would pass any test whatsoever. As a matter of fact, any assignment of a pointer to number is frowned upon.

Edit: Since you edited your original example: long and unsigned int (or size_t) are not mutually assignable. At very least, there's the sign issue.

Bottom line is: Windows API wasn't designed for portability, so it's not only full of hacks, but much of its design is flawed from that perspective.

Share this post

Link to post
Share on other sites
Yeah, I changed the "hwnd" example for exactly the reason you pointed out. I was trying to come up with a trivial example off the top of my head...

As far as "long" to "size_t", it's really a trivial example. I could have used "unsigned long". VS2005 still spits out a C4312 on anything resembling the SetWindowLongPtr that I've described.

Casting to (LONG_PTR) (which is signed) has the same effect.

My question was really is the /Wp64 switch really necessary, when the 64-bit compiler is available itself? Why not just run the code through it, when wanting to create 64-bit code?

I guess the difficulty is in wanting to use 32-bit executables on 64-bit versions of Windows--but from what I'm led to believe, those run fine under WOW.

Share this post

Link to post
Share on other sites
I tried various static code checkers.

They trigger such warnings not only on one call, but you're likely to have your code littered with them.

I'm unable to currently point out a good example, but there's really lots of tricky details to watch when dealing with various types - overflow being the simplest of them.

Once you get down to pointers and pointer arithmetic, things get even worse.

These problems are incredibly unlikely to show up in practice, but that doesn't mean they should be ignored.

BTW: googling for your problem shows up it's an API foobar that causes that warning, where it shouldn't be.

So, yes and no. It is a portability issue, and no, it's not your fault, but the compiler is pointing out a problem in API. This is unfortunately likely to happen.

Share this post

Link to post
Share on other sites
Thanks for the link. I didn't think to look for specifically SetWindowLongPtr, since (as you said) the code had quite a few more of these warnings.

Casting to LONG_PTR didn't work in any of those cases either. /Wp64 switch is disabled now. When I run the code thru the 64-bit compiler, I'll turn it on.

Thanks again.

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  

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By muhamad rabee
      My first mobile game made by unity



      I appreciate every suggestion
    • By Simplepg
    • By Simplepg
    • By ForgedInteractive

      Who We Are
      We are Forged Interactive, a small team of like-minded game developers with the sole purpose of making games we love! We're a team of artists, animators, programmers, level designers, writers, composers, producers, and other creative minds. We want to make games that you, the modern gamer want to play! We hope to build a community that enjoys our games as much as we love creating them. With your feedback and support we will be able to achieve that.

      About the Game
      GAME NAME is a fun, action-packed army builder with unique characters, challenges and engaging levels. Set forth on an adventure to protect friends, family and countrymen from new adversaries. Once defeated your enemies turn coat and join you in your adventures. Players can enjoy a range of troops and abilities based on their gameplay style which become more important as maps introduce more challenging terrain, enemies and bosses. Strong orc knights, dangerous shamans, and even a dragon are out on the prowl. Knowing when to fight and when to run, and how to manage your army is essential. Your actions alone decide the fate of this world.

      Previous Work by Team
      Although we are working towards our first game as a team, our team members themselves have past experience in the industry.
      This includes members who have worked on titles including:
      Final Fantasy Kingsglaive, FIFA, Xcom 2 and Civilization.

      Who are we looking for? 3D Modellers Concept Artists Marketing Specialists Level Designer

      What do we expect? Reference work or portfolio. Examples what have you already done and what projects you have worked on academic or otherwise. The ability to commit to the project on a regular basis. If you are going on a two-week trip, we don't mind, but it would be good if you could commit 10+ hours to the project each week. Willingness to work with a royalty based compensation model, you will be paid when the game launches. Openness to learning new tools and techniques
      What can we offer? Continuous support and availability from our side. You have the ability to give design input, and creative say in the development of the game. Shown in credits on websites, in-game and more. Insight and contacts from within the Industry.
      If you are interested in knowing more or joining. Please email or PM us on Skype. Myself or Colin will reply to you within 48 hours.

      Skype: ForgedInteractive

      David and Colin

      Follow us on:

      Twitter: @ForgedInteract
    • By Eck
      I just saw their courses were knocked down to $10 each and figured I'd share the info here. They have stuff for Unity, Unreal, drawing, business, etc. I haven't used their stuff before, but the previews I looked at seemed pretty good and there is a user review system as well.
      - Eck
  • Popular Now