fuhsnn / slimcc

C11 compiler with GNU / C23 extensions for x86-64 Linux, able to build Python and PostgreSQL
MIT License
24 stars 3 forks source link

`va_arg()` struct argument read wrong #52

Closed fuhsnn closed 6 months ago

fuhsnn commented 6 months ago
#include <stdio.h>
#include <stdarg.h>
struct S {
    long i, j;
};
void fn(int cnt, ... ) {
    va_list ap;
    va_start(ap, cnt);
    for (int i = 0; i < cnt; i++) {
        struct S s = va_arg(ap, struct S);
        printf("%ld,%ld,", s.i, s.j); // expected 1,2,3,4,5,6
    }
    printf("\n");
    va_end(ap);
}
int main(void) {
    struct S s0 = {1,2};
    struct S s1 = {3,4};
    struct S s2 = {5,6};

    fn(3, s0, s1, s2);
}