File: variadic3.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 (31 lines) | stat: -rw-r--r-- 598 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
24
25
26
27
28
29
30
31
#include <stddef.h>
#include <stdarg.h>
#include "test.h"

typedef struct {
    long double ld;
} MyStruct;

void print_variadic(int count, ...) {
    va_list ap;
    va_start(ap, count);

    for (int i = 0; i < count; i++) {
        MyStruct s = va_arg(ap, MyStruct);
        printf("MyStruct[%d].ld = %Lf\n", i, s.ld);
        if (i == 0)
            ASSERT(1, s.ld);
        else if (i == 1)
            ASSERT(9, s.ld);
    }

    va_end(ap);
}

int main(void) {
    MyStruct a = {1.234567890123456789L};
    MyStruct b = {9.876543210987654321L};

    print_variadic(2, a, b);
    return 0;
}