• Advertisement
Sign in to follow this  

Unity warning C4312: /Wp64 switch of any use?

This topic is 3913 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
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
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By NDraskovic
      Hey guys,
      I have a really weird problem. I'm trying to get some data from a REST service. I'm using the following code:
      private void GetTheScores() { UnityWebRequest GetCommand = UnityWebRequest.Get(url); UnityWebRequestAsyncOperation operation = GetCommand.SendWebRequest(); if (!operation.webRequest.isNetworkError) { ResultsContainer rez = JsonUtility.FromJson<ResultsContainer>(operation.webRequest.downloadHandler.text); Debug.Log("Text: " + operation.webRequest.downloadHandler.text); } } The problem is that when I'm in Unity's editor, the request doesn't return anything (operation.webRequest.downloadHandler.text is empty, the Debug.Log command just prints "Text: "), but when I enter the debug mode and insert a breakpoint on that line, then it returns the text properly. Does anyone have an idea why is this happening?
      The real problem I'm trying to solve is that when I receive the text, I can't get the data from the JSON. The markup is really simple:
      [{"id":1,"name":"Player1"},{"id":2,"name":"Player2"}] and I have an object that should accept that data:
      [System.Serializable] public class ResultScript { public int id; public string name; } There is also a class that should accept the array of these objects (which the JSON is returning):
      [System.Serializable] public class ResultsContainer { public ResultScript[] results; } But when I run the code (in the debug mode, to get any result) I get an error: ArgumentException: JSON must represent an object type. I've googled it but none of the proposed solutions work for me.
      Also (regardless if I'm in the debug mode or not) when I try to do some string operations like removing or adding characters to the GET result, the functions return an empty string as a result
      Can you help me with any of these problems?
      Thank you
    • By nihitori
      The Emotional Music Vol. I pack focuses on beautiful and esoteric orchestral music, capable of creating truly emotive and intimate moods. It features detailed chamber strings, cello and piano as the main instruments, resulting in a subtle and elegant sound never before heard in video game royalty-free music assets.

      The pack includes 5 original tracks, as well as a total of 47 loops based on these tracks (long loops for simple use and short loops for custom / complex music layering).

      Unity Asset Store link: https://www.assetstore.unity3d.com/en/#!/content/107032
      Unreal Engine Marketplace link: https://www.unrealengine.com/marketplace/emotional-music-vol-i

      A 15 seconds preview of each main track is available on Soundcloud:
    • By RoKabium Games
      Another one of our new UI for #screenshotsaturday. This is the inventory screen for showing what animal fossils you have collected so far. #gamedev #indiedev #sama
    • By eldwin11929
      We're looking for programmers for our project.
      Our project is being made in Unity
      -Skills in Unity
      We're looking for programmers who can perform a variety of functions on our project.
      Project is a top-down hack-and-slash pvp dungeon-crawler like game. Game is entirely multiplayer based, using randomized dungeons, and a unique combat system with emphasis on gameplay.
      We have a GDD to work off of, and a Lead Programmer you would work under.
      Assignments may include:
      -Creating new scripts of varying degrees specific to the project (mostly server-side, but sometimes client-side)
      -Assembling already created monsters/characters with existing or non-existing code.
      -Creating VFX
      -Assembling already created environment models
      If interested, please contact: eldwin11929@yahoo.com
      This project is unpaid, but with royalties.
      Additional Project Info:
      Bassetune Reapers is a Player-verus-Player, competitive dungeon crawler. This basically takes on aspects of dungeon crawling, but with a more aggressive setting. Players will have the option to play as the "dungeon-crawlers" (called the 'Knights', or "Knight Class", in-game) or as the "dungeon" itself (literally called the 'Bosses', or "Boss Class", in-game). What this means is that players can choose to play as the people invading the dungeon, or as the dungeon-holders themselves.
      Key Features:
      -Intense, fast-paced combat
      -Multiple skills, weapons, and ways to play the game
      -Tons of different Bosses, Minibosses, creatures and traps to utilize throughout the dungeon
      -Multiple unique environments
      -Interesting, detailed lore behind both the game and world
      -Intricate RPG system
      -Ladder and ranking system
      -Lots of customization for both classes s of customization for both classes
    • By RoKabium Games
      Custom coffee mugs have arrived... More caffeine!
      Have a great weekend everyone! 
      #gamedev #indiedev #sama #caffeine
  • Advertisement