<html><body><p>I tried to google for an answer but couldn't find anything. What is the correct way to do the following on Linux?<br><br><font size="2" face="Source Code Pro"> @_silgen_name("foo")</font><br><font size="2" face="Source Code Pro"> func foo(theInt: UInt)</font><br><font size="2" face="Source Code Pro"> -> (a: UInt, b: UInt, c: UInt)</font><br><br><font size="2" face="Source Code Pro"> var (d, e, f) = foo(aNum)</font><br><br>Where foo is:<br><br><font size="2" face="Source Code Pro"> typedef struct {</font><br><font size="2" face="Source Code Pro"> long a;</font><br><font size="2" face="Source Code Pro"> long b;</font><br><font size="2" face="Source Code Pro"> long c;</font><br><font size="2" face="Source Code Pro"> } Tuple;</font><br><br><font size="2" face="Source Code Pro"> extern "C" {</font><br><font size="2" face="Source Code Pro"> Tuple foo(int i) {</font><br><font size="2" face="Source Code Pro"> return Tuple{ i, i, i };</font><br><font size="2" face="Source Code Pro"> }</font><br><font size="2" face="Source Code Pro"> }</font><br><br>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><br>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><br>Thanks, Bryan<BR>
</body></html>