V
vaib
hi all ,
It really seems that C never ceases to amaze . All this time
i've been doing C and i thought i was quite adept at it but i was
wrong . So without wasting any more time , here's the confusion .
I read in K&R that ANSI introduced the concept of function
prototyping in C and it was missing there initially ( it borrowed the
concept from C++ ) _but_ it did it make it compulsory to actually
include the function declaration in the program , the reason being -
so that older C code ( the ones missing the declarations ) could
run on newer compilers too . So the situation now is this - if there
is no function declaration corresponding to the function call and the
call does not say anything about the return type then the compiler
should assume a declaration with an int return type . for example ,
main()
{ fun(3) ;
return 0 ;
}
in this case the compiler assumes this declaration - int fun( the
standard says nothing about the parameters so thats implementation
dependent ) ;
and the code compiles without any hitch .
my question is what sort of declaration would the
compiler assume in the following case :
main()
{
void * p ;
p = fun(3) ;
}
in the above case the return type is mentioned as void * .
also what happens in this case :
main()
{
void * p ;
p = malloc(sizeof(int)) ;
return 0 ;
}
the above code also compiles and _executes_ successfully on
gcc .
few more regarding these concepts have cropped up lately in my mind
but i'll ask them as the thread proceeds .
Thanking in anticipation . Vaib .
It really seems that C never ceases to amaze . All this time
i've been doing C and i thought i was quite adept at it but i was
wrong . So without wasting any more time , here's the confusion .
I read in K&R that ANSI introduced the concept of function
prototyping in C and it was missing there initially ( it borrowed the
concept from C++ ) _but_ it did it make it compulsory to actually
include the function declaration in the program , the reason being -
so that older C code ( the ones missing the declarations ) could
run on newer compilers too . So the situation now is this - if there
is no function declaration corresponding to the function call and the
call does not say anything about the return type then the compiler
should assume a declaration with an int return type . for example ,
main()
{ fun(3) ;
return 0 ;
}
in this case the compiler assumes this declaration - int fun( the
standard says nothing about the parameters so thats implementation
dependent ) ;
and the code compiles without any hitch .
my question is what sort of declaration would the
compiler assume in the following case :
main()
{
void * p ;
p = fun(3) ;
}
in the above case the return type is mentioned as void * .
also what happens in this case :
main()
{
void * p ;
p = malloc(sizeof(int)) ;
return 0 ;
}
the above code also compiles and _executes_ successfully on
gcc .
few more regarding these concepts have cropped up lately in my mind
but i'll ask them as the thread proceeds .
Thanking in anticipation . Vaib .