I need to define a system-dependent integer type, in order to be compatible with some low-level librarys. I've setup a x86 and x64 Project-Configuration, and defined conditional compilation symbols for them (IA32 and INTEL64).
So, I would like to do the following:
#if IA32
typedef int SysInt;
typedef uint SysUInt;
#elif INTEL64
typedef long SysInt;
typedef ulong SysUInt;
#endif
However, that doesn't work due to typedef is not available in C#. What's the best option to implement this?
Thanks in advance. Best regards.
You want IntPtr
and UIntPtr
, which are 32 bits in 32-bit processes and 64 bits in 64-bit processes. Since these types automatically take the process's "bitness", there's no need for conditional compilation or two different projects configurations in order to use them.
If you actually want to do math on the values, though, you should cast them to long
or ulong
to do the math and then back to IntPtr
or UIntPtr
to pass them to your external libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With