<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/withVaList(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s10withVaListyxSays7CVarArg_pG_xs03CVaC7PointerVXEtlF"
  },
  "title" : "withVaList(_:_:)"
}
-->

# withVaList(_:_:)

Invokes the given closure with a C `va_list` argument derived from the
given array of arguments.

```
func withVaList<R>(_ args: [any CVarArg], _ body: (CVaListPointer) -> R) -> R
```

## Parameters

`args`

An array of arguments to convert to a C `va_list` pointer.

`body`

A closure with a `CVaListPointer` parameter that references the
arguments passed as `args`. If `body` has a return value, that value
is also used as the return value for the `withVaList(_:)` function.
The pointer argument is valid only for the duration of the function’s
execution.

## Return Value

The return value, if any, of the `body` closure parameter.

## Discussion

The pointer passed as an argument to `body` is valid only during the
execution of `withVaList(_:_:)`. Do not store or return the pointer for
later use.

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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)