If you define two separate identifiers of the same name for different objects in the same namespace, they may overlap. C11 standard, chapters Β§6.2.1,
If the identifier denotes two different objects with the same name space, the areas may overlap ....
Note: why in this case both sum are in the namespace with the name
So, as soon as you redefine the identifier with a different type,
.... If so, the volume of one object (internal volume) will end strictly in front of the area of ββanother object (external coverage). Within the inner region, an identifier denotes an object declared in the inner region; an object declared in the outer region is hidden (and not displayed) in the inner region.
This means essentially in your case the inner function sum() , when you define int sum , basically you are obscuring the sum function. After overriding, sum is an identifier of type int in this scope. Thus, inside the sum() function, you cannot make a call to sum() , which is now an int type.
However, FWIW, the call to sum() in main() (or rather, outside of sum() ) must be valid, since at that moment int sum will be unavailable.
Solution: Change the variable name int sum to something else.
Thanks @pmg for correction
EDIT:
As mentioned in another @juanchopanza answer , after changing the name of the shadow variable, your program will compile, and as soon as you run it, you will encounter infinite recursion due to the unconditional call to sum() inside sum() . You need to add an interrupt condition to complete ( return from) the recursion.
Footnote:
Turning to C11 , chapter Β§6.2.3 , namespaces, we can say that there are separate namespaces for different categories of identifiers, for example. 1) label names 2) tags of structures, unions and transfers, 3) members of structures or unions, and 4) all other identifiers.
So, in this particular case, the sum() function and the int sum definition will be in the same namespace, for the sum() scope