19

Be Careful with Parameterless C Functions

Instead of this:

int foo();

Declare it like this:

int foo(void);
#SecureCoding #C/C++

When a C function does not take any arguments, it might be tempting to simply declare it as e.g. int foo();.

For historical reasons the compiler interprets this declaration as a function with an unknown list of arguments. The compiler essentially treats it as int foo(...);. This can cause issues and allows calling it by accident with arguments.

The correct way to declare a C function with no arguments is as int foo(void);

Icon with a waving hand

Get in touch

sigma star gmbh
Eduard-Bodem-Gasse 6, 1st floor
6020 Innsbruck | Austria

sigma star gmbh logo