Keil Logo

va_start

Summary
#include <stdarg.h>

void va_start (
  argptr,         /* optional argument list */
  prevparm);      /* arg preceding optional args */
Description

The va_start macro, when used in a function with a variable-length argument list, initializes argptr for subsequent use by the va_arg and va_end macros. The prevparm argument must be the name of the function argument immediately preceding the optional arguments specified by ellipses ('...'). This routine must be called to initialize a variable-length argument list pointer before any access using the va_arg macro is made.

Return Value

None.

See Also

va_arg, va_end

Example
#include <stdarg.h>
#include <stdio.h> /* for printf */

int varfunc (char *buf, int id, ...) {
  va_list tag;

  va_start (tag, id);

  if (id == 0) {
    int arg1;
    char *arg2;
    long arg3;

    arg1 = va_arg (tag, int);
    arg2 = va_arg (tag, char *);
    arg3 = va_arg (tag, long);
  }

  else {
    char *arg1;
    char *arg2;
    long arg3;

    arg1 = va_arg (tag, char *);
    arg2 = va_arg (tag, char *);
    arg3 = va_arg (tag, long);
  }

  va_end (tag);
}

void caller (void) {
  char tmp_buffer [10];

  varfunc (tmp_buffer, 0, 27, "Test Code", 100L);
  varfunc (tmp_buffer, 1, "Test", "Code", 348L);
}
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.