Thread: Where are the functions?

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    32

    Where are the functions?

    I'm confused where the actual code is for a function from an included header. For example, if I include math.h, then i can use the sqrt() function(among others), but where is sqrt()'s actual code, and where in math.h does it tell the compiler where the code is?

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    was tryin to find a previous post that explained ur question but i can't seem to find it.

    anyway, the header files only contain (function wise anyway) only function prototypes. Thats all the compiler needs to know at compile time, just each function signature. The actual code for the functions are in binary in object files. The linker links the functions from each object file to the other.

    So when u compiler say a .cpp file with printf, and compile it, it is compiled into an object file. This file is in binary, but the actual function names still exists in the file. The linker sees the function name and looks for it in the other object file. It then links the name and produces a full executable (entirely binary).

    these object files are .lib file (library file). The ones that you would produce using say gcc would be .o (object) files.
    Last edited by Kyro; 11-05-2003 at 11:41 PM.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    32
    Is it possible to get the C/C++ code for the object library files, or is it written in assembly or not distributed?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I think this site's FAQ deals with this:

    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM