[Mono-list] PInvoke Conventions

Rhys Weatherley rweather@zip.com.au
Thu, 19 Jul 2001 11:20:53 +1000

Tomas Restrepo wrote:

> That's correct. Personally, I don't see much need to overload it. But that
> aside, I don't see the problem of dealing with native sized values as such a
> big deal. While nor the ECMA, nor MS say it a lot, using P/Invoke does, in
> more ways than one, leave platform independence out of the question.

Yep, PInvoke does make things platform-dependent.  What I'm
hoping though is that we can make it platform-dependent to
"Unix in general", rather than dependent to Linux, BSD, Solaris,
AIX, etc, etc, etc.

> > Sam, perhaps it could be adjusted slightly to say "if the
> > class is marked explicit, but no explicit information is supplied,
> > then use the platform-specific conventions".
> Isn't that what SequentialLayout means, anyway?

No, SequentialLayout means the default rules for layout of the
object that is used by the CLR.  The CLR is not required to follow
the rules used by the underlying platform.  For example, C
normally packs bytes with byte-alignment, but the CLR may
choose to extend the field to a full word because it may make
loads from objects to the stack faster on some platforms.

The "explict layout" flag indicates that the CLR must adhere
to what it is told, and must not adjust things to suit its own
implementation requirements.

> The ECMA spec doesn't say it
> out loud, but I presume it is expected to use the default packing in that
> case. If, instead it implies a packing of 1, then one could suggest the
> attribute is extended to support an argument telling it what packing to use,
> which seems clearer that using explicit in this case (at least to me).

There already is a packing attribute, which turns into a "ClassLayout"
token in the metadata.  So, Microsoft has already dealt with that issue.