Archived

This topic is now archived and is closed to further replies.

An integer type that's always the same width as the address bus.

This topic is 5153 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 just got hold of VS.NET (Not planning to use managed code at all), and compiled some of my previous source on it. It gives me a horde of warnings about typecasts from pointers to integer values: warning C4311: ''type cast'' : pointer truncation from ''void *'' to ''u32'' warning C4312: ''type cast'' : conversion from ''u32'' to ''u8 *'' of greater size AFAIK I''m still compiling for a 32-bit environment. u32 is a typedef of __int32. (The actual variable type giving the warning is uADDR, which is (in this case) a typedef of u32, but somehow the compiler choses to print "u32". Now the integer type I am using (called uADDR), is (manually or automatically) typedef''d to the integer type that is the same size as the address bus. I assume the warning is because of the possible assumed loss of data when my code is ported to 64-bit, since the compiler doesn''t know that the precision of uADDR will change. What I want to know is: 1) Is there a cross-platform integer type I can use that is the same width as the address bus and will prevent these warnings? 2) Is there another way to prevent these warnings (I don''t want to turn down the warning level, I like being told when I am converting a double to an integer than I might lose precision). 3) What is the easiest way to tell whether the project you are coding in under VS.NET is going to generate a managed target (As I said, I am new to VS.NET, and want to ensure that my code is pure machine code, none of this ''IL'' stuff. I''m just using the simple Win32 C++ project type. Thanks for all assistance.

Share this post


Link to post
Share on other sites
quote:
I assume the warning is because of the possible assumed loss of data when my code is ported to 64-bit

Correct.
quote:
1) Is there a cross-platform integer type I can use that is the same width as the address bus and will prevent these warnings?

Isn''t it int? If it isn''t I''m sure the C99 header stdint will be of use for you, they have a ''fast'' set of integer sizes.
quote:
2) Is there another way to prevent these warnings (I don''t want to turn down the warning level, I like being told when I am converting a double to an integer than I might lose precision).

There is a project setting under C++ -> General called "Detect 64-bit Portability Issues." Try disabling it.

If that doesn''t work, use pragma pop/push around the code. Silly, but effective.

And that warning is really annoying. I switched to the 64-bit ready version of SetWindowLongPtr and it still emits the warning.
quote:
3) What is the easiest way to tell whether the project you are coding in under VS.NET is going to generate a managed target (As I said, I am new to VS.NET, and want to ensure that my code is pure machine code, none of this ''IL'' stuff. I''m just using the simple Win32 C++ project type.

It''s not pure machine code, just assembly.

The project is either managed or unmanaged when you make it. Converted projects are unmanaged. You are only using a managed project if you specify it. Under General project settings, it is called "Use Managed Extensions." Just make sure it is No and you are fine.

Share this post


Link to post
Share on other sites
Yep, turning off the "Detect 64-bit Portability Issues" worked perfectly, thanks.

It''s not pure machine code, just assembly.
Well, eventually it''s machine code if it''s built. Hmm what''s the term for machine code that is native to the platform that it is running on (As opposed to Java byte-code on x86, which can still be called "machine code" since it works on the JVM (And the picojava)).

Share this post


Link to post
Share on other sites
hmm, VS.NET doesn't seem to have [stdint.h] Kinda annoying, cos it looks like a better version of what I hacked together myself.

edit - removed the greater-that / less-than symbols around stdint.h. How do you write them without the forum thinking it's a tag?

[edited by - Krylloan on November 6, 2003 2:04:10 PM]

Share this post


Link to post
Share on other sites