mercredi 30 avril 2014

Why is `int` datatype not mandatory to be mentioned for function arguments in the function definition?


Vote count:

0




Recently I went through some code similar to this: (The code is proprietary, and hence adding a similar one)



#include<stdio.h>

void test_it(var)
{
printf("%d\n",var);
}

int main()
{
test_it(67);
return 0;
}


The arguments of test_it do not have datatype mentioned.


I compiled it as gcc test_it.c ... : Surprisingly No Warnings/Error


Again I compiled using: gcc -Wall test_it.c ... : No Warnings/Error yet again


(Getting more aggressive now...)


I compiled it again using: gcc -Wall -Wextra test_it.c ... :

warning: type of ‘var’ defaults to ‘int’ finally I got the warning.


I tried using multiple arguments as:



void test_it(var1, var2)
{
printf("%d\n%d\n",var1, var2);
}

int main()
{
test_it(67,76);
return 0;
}


Same beahavior!!


Also I tried this:



void test_it(var)
{
printf("%d\n",var);
}

main() // Notice that no `int` there
{
test_it(67);
return 0;
}


This code gave warning with -Wall option only.


So my question is why the int datatype is not mandatory for function arguments in function definition?



asked 44 secs ago






Aucun commentaire:

Enregistrer un commentaire