Handmade Network»Forums
131 posts
Macro for function pointer
#define funcdecl(output, name, ...) output (*name)(VA_ARGS)

void DoA(int a, char b)
{
    a += 1;
    b = 'c';
}

int main(void)
{
    void (*A)(int);
    A(); // Error
    funcdecl(void, Do, int a, char b) = DoA;
    Do(0, 'c');
    Do(); // Not error

    return 0;
}

I was testing some macro in Godbolt and for some reason, if I call A() then the compiler said "too few arguments for call" but if I just call Do() with no arguments then it's fine. Why is that?

131 posts
Macro for function pointer

Wow, I'm so stupid. It should be __VA_ARGS__ not VA_ARGS. But, weirdly, the compiler doesn't say anything.