Function Scopes

Function definitions open a new local scope.
The function’s parameters belong to this local scope. Blocks additionally open new local scopes

Does this mean, that whenever a function is defined, two local scopes are created - one for the function’s parameters and one for the block? Or is it just one for both the block and the function’s parameters.

E.g is this allowed:

void test(int x) {
    char x;

or would this be a redeclaration of the variable x in the same scope, as C would handle it?

Figure 3 on page 7 answers this for the case where the types of both declarations are the same, but maybe your question is specifically about redeclaration of a variable name with a new type?

In any case what is the value of having a separate scope for the parameters of a function definition? You can not do anything in that scope and the information belongs to the body of the function, it has no meaning outside of it. (and for that reason the parameter list of a function declaration is thrown away during parsing)

1 Like

This is not allowed. Neither in C, nor in TinyC. Neither language allows redeclarations in the local scope, and further even if so they would not be allowed to change the type.