Search code examples
cvisual-studiogcccl

Compiler warning - something differs in parameter lists


I'm trying to compile the following source code which successfully compiles on both gcc and Microsoft's cl.exe.

void SomethingBeforeExit();

void SomethingBeforeExit()
{
    // some code
    _exit(0);
}

int main(int argc, char *argv[])
{
    // some code
    atexit(SomethingBeforeExit);
}

However, I'm getting a C4113 warning from cl.exe with the following message:

SomeCode.c(10): warning C4113: 'void (__cdecl *)()' differs in parameter lists from 'void (__cdecl *)(void)'

As I said, the source code still compiles successfully and appears to work. My goal is to prevent this warning from happening in cl, as gcc doesn't generate any warnings upon compilation.

I assume that the declaration of that function is not being treated as void SomethingBeforeExit(void), however, I don't know how to specifically declare a function's parameter list as void.

I'm using VS14 and C/C++ 19.00.23918 for x86 for cl.exe and gcc v5.4.0 compilers to compare generated warnings.


Solution

  • In C, empty parentheses in a function declaration doesn't mean "no parameters." Instead, it means any number of parameters (similar to ... in C++). Perhaps what you meant to declare was void SomethingBeforeExit(void).