[Mono-list] PInvoke Conventions
Rhys Weatherley
rweather@zip.com.au
Thu, 19 Jul 2001 09:55:18 +1000
Sam Ruby wrote:
> If I read those conventions correctly, when run on a 64/64 system, a native
> C function could return a 64 bit "int" and that would be truncated to 32
> bits. How are overflows handled?
Right now, they aren't - it just truncates. The problem also occurs
in a "long" parameter on a 32/32 system. Truncation is one of the
drawbacks of this system. I just couldn't come up with any other
way to do this cleanly.
This is partly why I'd like the "NativeTypeSizes(true)" behaviour
to be specified explicitly, rather than being the default as Bob
suggested in an earlier message in the thread. i.e. the programmer
has to know what they are doing and explicitly mark the PInvoke
as a potentional source of platform issues.
In practice, it may not be too big of an issue for people using
PInvoke functions. Most PInvokes are likely to be wrapped up
tight behind some other API. e.g. "read", "write", "lseek", etc
will be wrapped up behind C# streams. The stream implementor
can ensure that they handle boundary cases correctly (e.g.
by using "lseek64" instead of "lseek").
Cheers,
Rhys.