(I have this uneasy feeling that I've asked this before, but now I can't find it. Feel free to close and redirect this question if so...)
In C, assume I have a function named thing() and some other function that uses thing as a formal parameter:
thing_t *thing(int id) { ... function that returns a *thing_t ... }
void foo(thing_t *thing) { ... function that takes a *thing_t as an argument ... }
Inside the body of foo(), is there any guarantee that thing refers to the passed-in parameter as opposed to the function of the same name? Do any of the C specifications have anything to say about this?
(And yes, I'd agree that this is dubious coding style...)
The definition of the function
thingdeclaresthingas an identifier with file scope, per C 2018 6.2.1 4. Its scope extends from its declaration (specifically, from the end of its declarator,*thing(int id)) to the end of the translation unit.The definition of the parameter
thingin the definition offoodeclaresthingas an identifier with block scope, also per 6.2.1 4. Its scope extends from its declaration to the end of the block that is the body of the function definition.Then the final sentences of 6.2.1 4 tells us that within
foo,thingrefers to the parameter, not the function: