To greatly simplify p/invoke code (particularly struct definitions, but also method signatures), it would be amazing if there was a "long" type that matched the OS's compiler definition of long. This would mean no more preprocessor definitions, and a single assembly that works with native libraries compiled for multiple OSes.
Here's an example of what you have to do in .net right now to p/invoke ogg_packet, defined here:
C code:
typedef struct {
unsigned char *packet;
long bytes;
long b_o_s;
long e_o_s;
ogg_int64_t granulepos;
ogg_int64_t packetno;
} ogg_packet;
C# code:
[StructLayout(LayoutKind.Sequential)]
struct OggPacket
{
IntPtr Packet;
#if WINDOWS // long is always 4 bytes on Windows
int Bytes;
int BeginningOfStream;
int EndOfStream;
#else // long matches the word length on Linux/OSX
IntPtr Bytes;
IntPtr BeginningOfStream;
IntPtr EndOfStream;
#endif
long GranulePosition;
long PacketNumber;
}
Ugly, and I need to ship separate binaries for Windows and OSX/Linux.
To be clear, this is partly about word length and partly about what "long" means in compiled C code on Windows (vs basically every other OS):
| Type |
Windows 32-bit |
Windows 64-bit |
*nix 32-bit |
*nix 64-bit |
| C# IntPtr |
4 |
8 |
4 |
8 |
| C# int (Int32) |
4 |
4 |
4 |
4 |
| C# long (Int64) |
8 |
8 |
8 |
8 |
| C long (no managed equivalent) |
4 |
4 |
4 |
8 |
https://software.intel.com/en-us/articles/size-of-long-integer-type-on-different-architecture-and-os/
I get that this is technically up to the compiler, not the OS, but I believe the dust has settled on these sizes since the shift from 16->32->64 bits.
To greatly simplify p/invoke code (particularly struct definitions, but also method signatures), it would be amazing if there was a "long" type that matched the OS's compiler definition of long. This would mean no more preprocessor definitions, and a single assembly that works with native libraries compiled for multiple OSes.
Here's an example of what you have to do in .net right now to p/invoke ogg_packet, defined here:
C code:
C# code:
Ugly, and I need to ship separate binaries for Windows and OSX/Linux.
To be clear, this is partly about word length and partly about what "long" means in compiled C code on Windows (vs basically every other OS):
https://software.intel.com/en-us/articles/size-of-long-integer-type-on-different-architecture-and-os/
I get that this is technically up to the compiler, not the OS, but I believe the dust has settled on these sizes since the shift from 16->32->64 bits.