This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

query:definition of func in C

Hi all

 include<stdio.h>
 #define ....

 void xyz();        <---- i am referring to this defn of xyz()

 void abc()
  {
   -:statements:-
  }

 void main()
  {
     abc();
     xyz();
  }

 void xyz()
  {
   -:statements:-
  }
      

Is it compulsory to define all the Routines,which are called from main ?(except extern)
ie xyz() was defined at the begginng of the program,but abc() was not defined.
is it so because during compilation,compiler have already met with abc()
before being called from main().

Thanks
Arjun

Parents
  • "A definition of a function may be provided by a prototype"

    Strictly, a Prototype provides only a declaration of a function; a matching definition must also be provided.

    A declaration simply informs the compiler about the function - it gives just enough information to allow the compiler to generate calls to the function, and handle any return value; ie, the function name, the number & type of any parameters, and the type of any return value.

    The definition provides the actual executable code to implement the function - the definition does not have to be in the same source file, or even the same language!
    The Linker sorts this out - or gives an "Unresolved External" error if it can't!

    As Graham said, you need to read-up on this in any standard 'C' textbook.

Reply
  • "A definition of a function may be provided by a prototype"

    Strictly, a Prototype provides only a declaration of a function; a matching definition must also be provided.

    A declaration simply informs the compiler about the function - it gives just enough information to allow the compiler to generate calls to the function, and handle any return value; ie, the function name, the number & type of any parameters, and the type of any return value.

    The definition provides the actual executable code to implement the function - the definition does not have to be in the same source file, or even the same language!
    The Linker sorts this out - or gives an "Unresolved External" error if it can't!

    As Graham said, you need to read-up on this in any standard 'C' textbook.

Children