<div dir="ltr">Thanks Joe, this is incredibly helpful, especially the note about how enums are passed in 'piecewise'.<div><br></div><div>re. your question: I was indeed calling the C++ function from Swift and directly passing in the enum (in pseudo-Swift):</div><div>let myEnum : SomeEnumType = ...</div><div>cplusplusFunction(value: myEnum, type: SomeEnumType.self) // incorrect</div><div><br></div><div>How would I pass a pointer to the enum's value from Swift? I don't think Swift exposes any mechanism to get the memory address of a Swift object. Perhaps I should create an UnsafeMutablePointer<SomeEnumType>, set its memory to (a copy of) the enum value, and pass that pointer object in instead?</div><div><br></div><div>Austin</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 12:04 PM, Joe Groff <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Jan 1, 2016, at 10:58 PM, Austin Zheng via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:<br>
><br>
</span><span class="">> Hello,<br>
> (...)</span><div><div class="h5">
<br>
</div></div>Swift structs are (currently) passed by passing each stored property individually. _EnumMirror is defined as a struct with owner/value/type fields, and the 'self' parameter to its methods gets broken down this way.<br>
<span class=""><br>
> * What I really want to do is to get the tag of an enum. I wrote a different entry point that omits the unused "owner" property and simply calls swift_EnumMirror_caseName with nullptr as the first argument. This other C++ function takes 'value' (an OpaqueValue*) and 'type' (a Metadata*). I've surmised that 'type' should be the Swift metatype of the enum instance (e.g. myEnum.dynamicType), and I do get the case names table. However, if I pass in the enum instance itself as 'value', my tag is always retrieved as 0. I noticed that there's some sort of indirection in the form of "vw_getEnumTag", which goes through something called the "value witness". Is there somewhere I can read up about the value witness concept? I assume the reason the 'original' code worked was because it was passing in a different object as 'value', maybe one that could serve as a value witness for the reflected-upon instance's type.<br>
<br>
</span>'value' is a pointer to the value in memory, not the value itself. Are you passing the enum's literal representation by value instead of passing a pointer to it?<br>
<span class="HOEnZb"><font color="#888888"><br>
-Joe<br>
<br>
</font></span></blockquote></div><br></div></div></div>