Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Confusion in AN...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 4284 of 4370
Post > Topic >>

Confusion in ANSI C's function concepts

by vaib <vaibhavpanghal@[EMAIL PROTECTED] > Sep 24, 2008 at 11:12 AM

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 .
 




 4 Posts in Topic:
Confusion in ANSI C's function concepts
vaib <vaibhavpanghal@[  2008-09-24 11:12:16 
Re: Confusion in ANSI C's function concepts
Barry Schwarz <schwarz  2008-09-24 19:17:46 
Re: Confusion in ANSI C's function concepts
Jack Klein <jackklein@  2008-09-24 21:36:25 
Re: Confusion in ANSI C's function concepts
Barry Schwarz <schwarz  2008-09-24 22:24:17 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 11:59:53 CST 2008.