views:

611

answers:

2

I've read (in Nish Sivakumar's book C++/CLI In Action among other places) that you should use the __clrcall decorator on function calls to avoid double-thunking, in cases where you know that the method will never be called from unmanaged code. Nish also says that if the method signature contains any CLR types, then the JIT compiler will automatically add the __clrcall. What is not clear to me is if I need to include __clrcall when I create C++/CLI properties. In one sense, properties are only accessible from .NET languages, on the other hand the C++/CLI compiler (I think) just generates methods (e.g. ***_get() ) that are callable from both managed and unmanaged code. So do I need to use the __clrcall modifier on my properties, and if so, where does it go? On the get/set functions themselves?

+1  A: 

I don't know the answer, but it seems a quick look in ildasm or Reflector would give you the answer.

If you do this, you should post it here.

Michael Burr
+2  A: 

@Mike B - Thanks for the tip on ildasm - I didn't know about that tool.

It appears that I misread/misunderstood Nish - the __clrcall modifier and the double-thunking problem it eliminates only apply to methods of NATIVE classes. All methods of Managed classes are __clrcall by default - which seems obvious in retrospect.

Evidently Marcus Heege's book Expert C++/CLI is available as a free download, and it has a nice table on page 215 that summarizes the calling conventions.

Brian Stewart
Thanks for the follow-up.
Michael Burr