### Function

# GLib Variant new_va

since: 2.24

#### Declaration

    GVariant*
    g_variant_new_va (
      const gchar* format_string,
      const gchar** endptr,
      va_list* app
    )

#### Description

This function is intended to be used by libraries based on `GVariant` that want to provide g_variant_new()-like functionality to their users.

The API is more general than `g_variant_new()` to allow a wider range of possible uses.

`format_string` must still point to a valid format string, but it only needs to be nul-terminated if `endptr` is `NULL`. If `endptr` is non-`NULL` then it is updated to point to the first character past the end of the format string.

`app` is a pointer to a #va_list. The arguments, according to `format_string`, are collected from this #va_list and the list is left pointing to the argument following the last.

Note that the arguments in `app` must be of the correct width for their types specified in `format_string` when collected into the #va_list. See the [GVariant varargs documentation][gvariant-varargs].

These two generalisations allow mixing of multiple calls to `g_variant_new_va()` and `g_variant_get_va()` within a single actual varargs call by the user.

The return value will be floating if it was a newly created GVariant instance (for example, if the format string was “(ii)”). In the case that the format_string was ‘*’, ‘?’, ‘r’, or a format starting with ‘@’ then the collected `GVariant` pointer will be returned unmodified, without adding any additional references.

In order to behave correctly in all cases it is necessary for the calling function to `g_variant_ref_sink()` the return result before returning control to the user that originally provided the pointer. At this point, the caller will have their own full reference to the result. This can also be done by adding the result to a container, or by passing it to another `g_variant_new()` call.

Available since: 2.24

This function is not directly available to language bindings.

#### Parameters

`format_string`

  Type: `const gchar*`

  A string that is prefixed with a format string.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`endptr`

  Type: `const gchar**`

  Location to store the end pointer, or `NULL`.

  The argument can be `NULL`.
  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`app`

  Type: `va_list*`

  A pointer to a #va_list.

  The data is owned by the caller of the function.

#### Return value

Type: `GVariant`

A new, usually floating, `GVariant`.

The caller of the function takes ownership of the data, and is responsible for freeing it.