logoalt Hacker News

CodeArtisantoday at 4:11 AM1 replyview on HN

Until C23, you could declare a pointer to a procedure that takes an unspecified amount of any type arguments like this

    void foo( int (*f)() )
    {
        f(1);
        f(1, "2" , 3.0);
    }
https://godbolt.org/z/s6e5rnqv9

If you compile with -std=c23, both gcc and clang will throw an error ( (*f)() is now the same as (*f)(void) )


Replies

AshamedCaptaintoday at 5:34 AM

You do not need the pointer at all. f() not specifying the arguments has been the case since forever. "Prototypes" (90s) are newer than C.