We are currently in the process of converting the website to the new design. Some pages, like this one, are still broken. We appreciate your patience.
Handmade Network»Forums
251 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?

251 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.