C code: how to detect duplicate function declarations

Is there a FLAG parameter in the makefile for detecting declarations of duplicate functions?

Duplicate function declarations found in the header file, but the compiler does not report this, even the FLAG is set as "warning as an error."

Does this lead to any implicit problem?

+4
source share
3 answers

You are trying to solve a problem that does not exist. As a rule, there are no problems with duplicate function declarations, therefore there is no reason for the compiler to diagnose them.

C , (, ).

( - ) - . , . , - - , ( ).

+1

, ?

:

1:

//definition
int func(void) {
...
}

2:

//declaration
extern int func(void);

3:

extern int func(void); //duplicate with source 2
0

I do not like to use extern, especially for functions. Declare your function in one header file, and then include this header file in other compilation units. If a function is used by only one compilation unit, declare it as static with the .c file itself.

0
source

All Articles