[swift-dev] C Macros and Variadic functions

Kate Stone katherine_stone at apple.com
Tue Jan 5 15:57:10 CST 2016


> On Jan 5, 2016, at 12:32 PM, Ryan Lovelett via swift-dev <swift-dev at swift.org> wrote:
> 
> Just to be clear though the intent of my question was not to quibble
> with compiler error messages. My real question is how are we meant to do
> systems programming with Swift on Linux if we cannot call ioctl?

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:

@_silgen_name("ioctl") func ioctl(fildes: CInt, request: UInt64, result: UnsafePointer<Int>) -> Int

… 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.

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.

Kate Stone k8stone at apple.com <mailto:k8stone at apple.com>
 Xcode Low Level Tools

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20160105/1eef0161/attachment.html>


More information about the swift-dev mailing list