Confusion in ANSI C's function concepts



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 .

.



Relevant Pages

  • Re: Share .cpp and .h along projects
    ... You asked me to show how a volatile pointer could be used to ... volatile void* or a cast could be used). ... As you stated "A compiler that can see into all these functions will ...
    (microsoft.public.vc.language)
  • Re: Confusion in ANSI Cs function concepts
    ... is no function declaration corresponding to the function call and the ... should assume a declaration with an int return type. ... the compiler will assume that fun is a function returning int ... in the above case the return type is mentioned as void *. ...
    (comp.lang.c)
  • Re: gcc knows about malloc()
    ... and may prevent the compiler from ... void *malloc; ... different effect than a different piece of C syntax in a declaration. ... and converting the bogus pointer to a pointer to function ...
    (comp.lang.c)
  • Re: void : bug or feature?
    ... X_To_2are entirely contained inside the scope of ClassA's definition. ... >> Note the line indicated by the asterisks above begins with a 'void'. ... > The indicated line is simply a function declaration. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: legality of forward declaration
    ... struct ForwardDeclared; ... void foo; ... gcc and Microsoft C compiler compile it ... declaration of your `struct`. ...
    (comp.lang.c)