[Mono-list] detecting param object[] foo

Paolo Molaro lupus@ximian.com
Thu, 6 Feb 2003 16:03:01 +0100

On 02/06/03 Sterling Hughes wrote:
> I've been playing around with detecting var arg style parameters (when I
> say that, I mean the C# equivalent, excuse a C programmer. :) For
> example:
> Console.WriteLine(string, param object[] foo)
> On the internals level, from what I see that is mapped to a
> MONO_TYPE_SZARRAY.  Are there any other distinguishing characteristics -
> I know lupus (on irc) mentioned something about detecting a sentinel,
> but I'm not sure exactly what that entails?  Are there any other

You asked about vararg, so I told you about the sentinel.
The 'params' modifier has nothing to do with vararg, though.

vararg is a CLR internal call convention, not accessible with standard
C# (though csc has some non-standard constructs for it) and it is
very similar to the C vararg stuff. In MonoMethodSignature we have the
sentinelpos field that specifies the first argument in the signature
that isn't a fixed argument.

The params keywork is, instead, a compiler thing: the number of
arguments is *fixed*, but one of the arguments is an array
and if the programmer passes items of the array, the compiler is
supposed to build an array under the hood and pass that.
The params keyword is stored in the metadata as a custom attribute for
the array paramenter: in C# you can access it with the standard
GetCustomAttributes() calls.
In the mono metadata API there is no specific call yet to do this,
but you can check what is involved in the metadata/reflection.c file
(function mono_reflection_get_custom_attrs).
If you file a bug report in bugzilla, I'll find the time to design and
implement an API to make the process easier from C code (unless, of
course, you want to contribute it:-).


lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better