11.1.5 Function definitions in K&R format (formal parameters of _Bool type)

When the function definition that includes a _Bool-type parameter is written in the K&R format, an assembly code that assigns the argument value to the _Bool-type parameter without change is generated. Therefore, if the _Bool-type
argument has a value other than 0 or 1, a value which is neither 0 nor 1 will be set to the parameter.

Example

void sub();
signed char c;
void func(void) {
        sub(2);
}
 
void sub(b)                     // 2 is set to parameter b.
_Bool b;
{
        if (b == 0 || b == 1) {
                c = b;
        } else {
                c = -1;         // -1 is set to c.
        }
}

 

(Workaround)

Write the function definition including a _Bool-type parameter and the function declaration in the function prototype
format.

void sub(_Bool);                // Function prototype
signed char c;
void func(void) {
        sub(2);
}
 
void sub(_Bool b)               // Function prototype
{
        if (b == 0 || b == 1) {
                c = b;
        } else {
                c = -1;
        }
}