First you have to clarify what size and format
long
is in both environments.
C++ and C#
long
types are two independent entities:
- C++ can be anything from 32 bit and above.
- C# is defined as 64 bit entity.
If you have access to the C++ source code and if you can compile it yourself, check for
#include <limits>
...
std::cout << "min long = " << std::numeric_limits<long>::min(); << std::endl;
std::cout << "max long = " << std::numeric_limits<long>::max(); << std::endl;
If
max long
results in
2147483647
, you have a 32 bit long type in C++.
If
max long
results in
9223372036854775807
, you have a 64 bit long type in C++.
If you have other values I would be surprised.
For 32 bit C++ long, try to read as C#
Int32
.
For 64 bit C++ long, try to read as C#
Int64
.
C++ structs may have padding bytes, but I guess with the given types, this is not an issue (no padding bytes).
Finally, the endian-ness might screw-up things too, i.e. if the C++ program runs on a big-endian system, the byte order is swapped compared to little-endian system. If the programs are compiled and run on the same system, this may usually be no issue, though.
If you design both applications (C++ and C#) yourself, you might consider to design a portable format that does not depend on padding bytes, endian-ness, and built-in type sizes (e.g.
json[
^], etc.).
Cheers
Andi