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()` error with function pointer type #51

Closed fuhsnn closed 6 months ago

fuhsnn commented 6 months ago
#include <stdio.h>
#include <stdarg.h>

void fn1(void) { printf("fn1\n"); }
void fn2(void) { printf("fn2\n"); }

void va_fn(int cnt, ...) {
    va_list ap;
    va_start(ap, cnt);
    for(int i = 0; i < cnt; i++) {
        va_arg(ap, void(*)(void))();
    }
    va_end(ap);
}

int main(void) {
    va_fn(2, &fn1, &fn2);
}

got

*(ty *)(klass == 0 ? __va_arg_gp(...
     ^ expected ')'
fuhsnn commented 5 months ago

This is actually a gcc/clang extension, the standard only covers pointer types obtainable by "simply by postfixing a *".