-1

What happens during the compilation and Linking process if the argument types are omitted(considering that the defined function takes arguments)? Will the compiler just mark the prototype with missing argument as a syntax error?

Edit

so I found out it builds and runs

#include<stdio.h>

float addf(a,b); // even without a,b it runs

    int main(){

        float input1 = 10.0;  
        float input2 = 20.0;

        printf("%f + %f = %f", input1, input2, addf(input1, input2) );

        getchar();

        return 0;
    }

float addf(float a, float b){

    return a + b;
}

result : 10.000000 + 20.000000 = 2.562500

Any idea why is it executed this way?

user2736738
  • 30,591
  • 5
  • 42
  • 56
Nas
  • 51
  • 1
  • 4

1 Answers1

1

The phrasing in the question is in error. You cannot omit the types in a function prototype. If you omit the types in function definition, declaration, it doesn't have a prototype. Only the declaration, definition that contains function types (be it just void) has a prototype.


When you do omit the types in a function definition, you get the old style* declaration-list. You must specify types for the parameters before the function body, an example of which can be seen here. The caller cannot know how to call this correctly, and the compiler cannot check. Scalar types are subject to default argument promotions, just like the variable-argument part of the prototyped functions.


As for the code in your question, it is not standards-compliant - in fact, there are 2 grave errors:

float addf(a,b); // even without a,b it runs

Is an incorrect declaration, that is not allowed by C - you must write

float addf();  // empty parentheses

and b, the actual parameters must be of type double, because the default argument promotions will convert them.