On my System:
sizeof(long) in c++ is 4 aka 32bits
sizeof(long) in c# is 8 aka 64 bits
So in my Interop method declarations I’ve been substituting c++ longs with c# int’s however I get the feeling this isn’t safe?
Why is a long the same size as an int in c++? And long long is 64bits? What’s next a long long long long??
Best thing to do assuming you have a recent C library is to
include <stdint.h>and useuint64_t,int64_t,uint32_t,int32_t. This will works regardless of model of the underlying platform.But if you are curious, the underlying issue is that different systems use different models. On 32 bit systems, both Posix and Windows use ILP32, which means an integer, long and point are all 32 bits long.
For 64 bits, Posix and Windows use different models.
Posix usually uses LP64 which means 32 bit integers, 64 bit longs and 64 bit pointers.
Windows uses LLP64 which means 32 bit integers and longs, 64 bit long longs and 64 bit pointers.