File: variadic2b.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (23 lines) | stat: -rw-r--r-- 360 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>

void test(const char *fmt, ...) {
  va_list ap;
  va_start(ap, fmt);

  // char is promoted to int in variadic arguments
  int c = va_arg(ap, int);

  printf("c = %d\n", c);
  assert(c == 42);

  va_end(ap);
}

int main() {
  char x = 42;
  test("char", x);
  printf("Test passed.\n");
  return 0;
}