Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c code: how to detect duplicate function declarations

Is there a FLAG setting in makefile to detect duplicate function declarations?

Duplicate function declarations in a header file are found, but compiler doesn't report it even FLAG is set as "warning as error".

Does this bring any implicit problem?

like image 718
blue_bonnet Avatar asked Mar 11 '16 15:03

blue_bonnet


1 Answers

You're trying to solve a problem that doesn't exist. There is generally no problem with duplicated function declarations, so there is no reason for a compiler to diagnose them.

A C compiler will typically diagnose situations, in the same compilation unit, where a function is declared in more than one way (e.g. two declarations of the same function with different return type or argument types).

Duplicate function definitions (a particular type of function declaration - which implements the function) are a problem. Practically, a compiler will give warnings or errors when multiple definitions of a function occur in a compilation unit. A linker will also report cases where a function is defined in more than one compilation unit - the exceptions being functions that are either inline or static (local to its compilation unit).

like image 70
Peter Avatar answered Oct 16 '22 13:10

Peter