I know it is wrong to use a function without prototype. But when I was fiddling around, I came across this strange and conflicting behavior.
test1
#include <stdio.h>
#include <limits.h>
void main(){
char c='\0';
float f=0.0;
xof(c,f);/* at this point implicit function declaration is
generated as int xof(int ,double ); */
}
int xof(char c,float f)
{
printf("%d %f\n", c,f);
}
Implicit function declaration would be int xof(int ,double );
error is
variablename.c:8:5: error: conflicting types for 'xof' int xof(char c,float f)
I understand this because implicitly generated function declaration (which defaults integer values to INT and decimals to DOUBLE) doesn't match the following function definition
test2
#include <stdio.h>
#include <limits.h>
void main(){
unsigned int a =UINT_MAX;
int b=0;
xof(a); /* implicit function declaration should be int xof(int); */
}
int xof(unsigned a,int b)
{
printf("%d %d\n", a,b);
}
implicit function declaration would be int xof(int); which should conflict with function definition
But this runs fine ( no error) and output is with 'a' behaving as 'int' value and 'b' has 'undefined Garbage'
-1 12260176
Could someone explain this. Thanks in advance.