<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></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 Jan 5, 2016, at 1:57 PM, Kate Stone 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 5, 2016, at 12:32 PM, Ryan Lovelett 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="">Just to be clear though the intent of my question was not to quibble<br class="">with compiler error messages. My real question is how are we meant to do<br class="">systems programming with Swift on Linux if we cannot call ioctl?<br class=""></div></div></blockquote><br class=""></div><div class="">In the absence of an automatic mechanism for importing the definition of variadic functions you can still define your own prototypes and bind them to the system implementation. For example, this declaration:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">@_silgen_name("ioctl") func ioctl(fildes: CInt, request: UInt64, result: UnsafePointer<Int>) -> Int</span></div><div class=""><br class=""></div></div>… gives you a non-variadic interface to ioctl that you can use for invocations that conform to this specific convention. You can define as many overloads as you wish, and so long as you’re cautious about which one you’re using for a given request you should be able to make progress.<div class=""><br class=""></div><div class="">The same basic strategy can be applied to any variadic functional interfaces. Ideally you’d want to hide this implementation detail behind a more Swift-friendly API where the request type is implied to create a more type-safe interface.</div></div></div></blockquote></div><br class=""><div class="">Don't do this. User code never has any business using underscored attributes. @_silgen_name produces an external reference to a Swift function, with Swift's calling convention. It cannot be safely used to refer to C functions, especially not variadic ones, since the convention for variadics in C is also different from non-variadic C functions. For variadic functions, you should write non-variadic wrappers in C (which can be static inline, to avoid wrapping overhead in production builds) and import them as Clang modules. See how open and fcntl are exported by the Darwin and Glibc overlays for an example.</div><div class=""><br class=""></div><div class="">-Joe</div></body></html>