---
title: CVarArg
framework: swift
role: symbol
role_heading: Protocol
path: swift/cvararg
---

# CVarArg

A type whose instances can be encoded, and appropriately passed, as elements of a C va_list.

## Declaration

```swift
protocol CVarArg
```

## Mentioned in

Using Imported C Functions in Swift

## Overview

Overview You use this protocol to present a native Swift interface to a C “varargs” API. For example, a program can import a C API like the one defined here: int c_api(int, va_list arguments) To create a wrapper for the c_api function, write a function that takes CVarArg arguments, and then call the imported C function using the withVaList(_:_:) function: func swiftAPI(_ x: Int, arguments: CVarArg...) -> Int {     return withVaList(arguments) { c_api(x, $0) } } Swift only imports C variadic functions that use a va_list for their arguments. C functions that use the ... syntax for variadic arguments are not imported, and therefore can’t be called using CVarArg arguments. If you need to pass an optional pointer as a CVarArg argument, use the Int(bitPattern:) initializer to interpret the optional pointer as an Int value, which has the same C variadic calling conventions as a pointer on all supported platforms. note: Declaring conformance to the CVarArg protocol for types defined outside the standard library is not supported.

## Relationships

### Conforming Types

- [Array](swift/array.md)
- [AutoreleasingUnsafeMutablePointer](swift/autoreleasingunsafemutablepointer.md)
- [Bool](swift/bool.md)
- [Dictionary](swift/dictionary.md)
- [Double](swift/double.md)
- [Float](swift/float.md)
- [Float80](swift/float80.md)
- [Int](swift/int.md)
- [Int16](swift/int16.md)
- [Int32](swift/int32.md)
- [Int64](swift/int64.md)
- [Int8](swift/int8.md)
- [OpaquePointer](swift/opaquepointer.md)
- [Set](swift/set.md)
- [String](swift/string.md)
- [UInt](swift/uint.md)
- [UInt16](swift/uint16.md)
- [UInt32](swift/uint32.md)
- [UInt64](swift/uint64.md)
- [UInt8](swift/uint8.md)
- [UnsafeMutablePointer](swift/unsafemutablepointer.md)
- [UnsafePointer](swift/unsafepointer.md)

## See Also

### C Variadic Functions

- [withVaList(_:_:)](swift/withvalist(_:_:).md)
- [CVaListPointer](swift/cvalistpointer.md)
- [getVaList(_:)](swift/getvalist(_:).md)
