Void argument in function definition but primitive data type in declaration

74 Views Asked by At

I have a query with below code. How does the below code gets interpreted as per K&R c? There is no compilation error and the code runs just fine. I have used -traditional in build option in codeblocks. Searched around for a while but could not get a satisfactory answer.

void func(int);

int main(void) {
    func(10);
    return 0;
}

void func(void){
}
1

There are 1 best solutions below

0
Jens On

How does the below code gets interpreted as per K&R C?

As code with a syntax error. K&R C does neither know about prototypes nor the void keyword (both were introduced with C89), so it is a syntax error.

Starting with C89, conflicting declarations are a constraint violation (fancy words for error) that must be diagnosed.