OiO.lk Blog C# Are multiple identical prototypes legal?
C#

Are multiple identical prototypes legal?


The following code does not emit any warnings when compiled with both gcc and clang on Linux x64:

#include <stdio.h>
#include <stdlib.h>

void foo(void);

void foo(void);

void foo(void);

int main(void)
{
    return 0;
}

IMO, it’s legal according to the following snippets from C99:

All declarations that refer to the same object or function shall have
compatible type; otherwise, the behavior is undefined.

(…)

For two function
types to be compatible, both shall specify compatible return types

(…)

Moreover, the parameter type lists, if both are present, shall agree in the
number of parameters and in use of the ellipsis terminator; corresponding
parameters shall have compatible types.

(…)

Two types have compatible type if their types are the same.

Am I right? I want to make sure it is not UB and that my understanding is correct.



You need to sign in to view this answers

Exit mobile version