Jump to content
  • Advertisement
Sign in to follow this  
Verg

Unity warning C4312: /Wp64 switch of any use?

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

After reading up on this for some time, and getting many threads like this one: http://www.gamedev.net/community/forums/topic.asp?topic_id=355259 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
Advertisement
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.

http://pluralsight.com/blogs/keith/archive/2005/01/13/4940.aspx

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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Aryndon
      Project Redemption is an semi-fantasy RPG with a linear story and an elaborate combat system.
      We are building in Unity and are currently looking animators and artists.
      What we are looking for
      -Someone who is okay with split revenue/profits when finished
      -Collaborate with others in the team. Do you have an idea/thought on what should be included? Tell us!
      -Someone who wants to work with people that are passionate about this project
      If you are interested. Please message me and I will get back to you as soon as possible! Or add me on Discord AJ#6664
    • By Aggrojag
      Hello!
      I'm working on a game that is a narrative driven dark comedy with some small aspects of platforming and puzzle solving. The project is rather small as well. It touches on topics such as suicide, mental illness, family, corruption, free-will, and redemption.
      This project is exercise in polish, this means some experimentation will be needed along with some reworking of assets as they're provided.
      This will be a revshare model.
      First, I'm looking for a 2D sprite artist, not pixelated, that can compliment the style of the attached images, and be similar to the temporary character.
      We are looking to bring on a SFX designer at this time. Full list of required SFX will be available upon request, as well as a build with all elements related to sound implemented in some form (many SFXs pulled from the web for now). Will likely require some field recording, and some pretty strange SFX for when things get weird. I imagine a good portion of these will be quite fun to create.
      Lastly, I'm looking for a male voice actor, English should be your primary language. There will be at minimum two characters that will need to be brought to life through vocals. The first voice is similar to Marvin from Hitchhiker's Guide to the Galaxy. A reference for the second voice would be a mix of Ren (Ren & Stimpy), and Android 21 (DragonBallFighterZ). Due to formatting, I'm not including YouTube links in the post, sorry.
       
      WIP Scene with our custom shaders attached (platforms are lazily placed, as this was an asset test):

      A scene with dynamic lighting and temp character:

       
      Unshaded asset:

      If you made it to the bottom, thank you, and I look forward to hearing from you.
    • By SickTwistGames
      Ok, firstly, Hi.
       
      This is my first post on this forum. I am an Indie Dev making my first game so bear with me when I say dumb stuff, I'm on a huge learning curve.
       
      My first question is about inventory systems for unity. I am trying to make a survival type game with crafting. I have purchased Inventory manager pro by devdog from the unity asset store and it seems like a pretty powerful assett but for an intermediate coder its a little tough to use.  I'm beginning to wonder if it was the right purchase.
      So my question is.... does anyone have any experience of inventory plugins / systems for unity and can anyone reccomend a system to me?
      It needs to have the following: Loot system, crafting system, character sheet, blueprint system,  character stats system. Ideally with as little coding as possible.
       
      Thanks
    • By ethancodes
      I've got a bug with my brick breaker style game. The bricks move down one line at a time ever 1.5 seconds. What appears to be happening is occasionally the ball will be just about to hit the brick when the brick moves down a line, and now the ball is behind it. I'm not sure how to fix this. I have two ideas but I'm not sure of implementation. 1 solution would be to check where they were and where they are going to be before rendering the frame. Then if they crossed paths, then register the brick as hit. Solution 2 would be change how the bricks move. I could maybe slide them down line by line, instead of a jump down. I'm not sure of this will fix the issue or not. Any ideas?
    • By Pixeye
      I wrote an extension for unity inspector that allows to group/fold variables. 
      Available on github  , cheers!

       
  • 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!