<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 22, 2016, at 5:57 AM, Bryan Chan via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><p class="">I tried to google for an answer but couldn't find anything. What is the correct way to do the following on Linux?<br class=""><br class=""><font size="2" face="Source Code Pro" class=""> @_silgen_name("foo")</font><br class=""><font size="2" face="Source Code Pro" class=""> func foo(theInt: UInt)</font><br class=""><font size="2" face="Source Code Pro" class=""> -> (a: UInt, b: UInt, c: UInt)</font><br class=""><br class=""><font size="2" face="Source Code Pro" class=""> var (d, e, f) = foo(aNum)</font><br class=""><br class="">Where foo is:<br class=""><br class=""><font size="2" face="Source Code Pro" class=""> typedef struct {</font><br class=""><font size="2" face="Source Code Pro" class=""> long a;</font><br class=""><font size="2" face="Source Code Pro" class=""> long b;</font><br class=""><font size="2" face="Source Code Pro" class=""> long c;</font><br class=""><font size="2" face="Source Code Pro" class=""> } Tuple;</font><br class=""><br class=""><font size="2" face="Source Code Pro" class=""> extern "C" {</font><br class=""><font size="2" face="Source Code Pro" class=""> Tuple foo(int i) {</font><br class=""><font size="2" face="Source Code Pro" class=""> return Tuple{ i, i, i };</font><br class=""><font size="2" face="Source Code Pro" class=""> }</font><br class=""><font size="2" face="Source Code Pro" class=""> }</font><br class=""><br class="">Currently, the call to foo crashes because foo wants to return the tuple indirectly, but the Swift call expects the three scalar return values in registers. This example is a generalization of runtime functions such as swift_class_getInstanceExtents, which happens to work because it only returns two scalars in RAX and RDX, which is supported by Clang. But my tests show that three-scalar tuples/structs will cause problems. On architectures where Clang only supports one scalar return value, the problem is worse.<br class=""><br class="">Am I doing something wrong or is there already a way to deal with this (e.g. annotation in Swift code to make it obey C ABI, or vice versa)?<br class=""></p></div></div></blockquote></div><div class="">Don't use @_silgen_name. If you want to use a C API from Swift, define a Clang module for its headers, and import the module. See <a href="http://clang.llvm.org/docs/Modules.html" class="">http://clang.llvm.org/docs/Modules.html</a> for documentation on Clang module maps.</div><div class=""><br class=""></div><div class="">-Joe</div></body></html>