conversions in 64 bit mode
-
in visual studio c++ / x64: what are way safest to convert from: 1.INT_PTR to int? 2.LRESULT to BOOL? 3.LRESULT to int?
There is no 'safe way' to do those 'conversions'. On
x64
theint
data type is a 32-bit integer, while bothINT_PTR
andLRESULT
are 64-bit integers (long long
, see Windows Data Types (BaseTsd.h) - Win32 apps | Microsoft Learn[^]), hence such conversions would 'narrow'. Also, I believe there is no 'safe way' to convert aLRESULT
to aBOOL
, because the former value depends on context (see, for instance, Writing the Window Procedure - Win32 apps | Microsoft Learn[^])."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
in visual studio c++ / x64: what are way safest to convert from: 1.INT_PTR to int? 2.LRESULT to BOOL? 3.LRESULT to int?
Hi, If you want to detect overflows, underflows, truncation. The Shell team provided the [intsafe.h header](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/).
wizQ wrote:
1.INT_PTR to int?
The [IntPtrToInt function](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/nf-intsafe-intptrtoint) will at least warn you if the pointer was truncated. CPallini gave great advice, there really isn't a "safe" conversion. But you can at least detect overflows and underflows.
-
Hi, If you want to detect overflows, underflows, truncation. The Shell team provided the [intsafe.h header](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/).
wizQ wrote:
1.INT_PTR to int?
The [IntPtrToInt function](https://learn.microsoft.com/en-us/windows/win32/api/intsafe/nf-intsafe-intptrtoint) will at least warn you if the pointer was truncated. CPallini gave great advice, there really isn't a "safe" conversion. But you can at least detect overflows and underflows.
-
can one change int to LRESULT?. change from int c = ... to LRESULT c = ... also change from void func(int p,.. to void func(LRESULT p,... :java: