Like Tree1Likes
  • 1 Post By Fordy

Location of library functions' implementations

This is a discussion on Location of library functions' implementations within the C Programming forums, part of the General Programming Boards category; Well I've been curious for a while as to where I can find the file(s) which show the actual implementation ...

  1. #1
    Registered User
    Join Date
    May 2010
    Location
    San Jose, California, United States
    Posts
    22

    Question Location of library functions' implementations

    Well I've been curious for a while as to where I can find the file(s) which show the actual implementation of library functions such as atoi(const char *str). I found the stdlib.h header file, but all that it contained was external declarations of all its functions:
    Code:
    ...
    extern double complex atoc(const char *);
    extern double atof(const char *);
    extern int atoi(const char *);
    extern long int atol(const char *);
    ...
    Then, using a debugger, I found that the atoi function actually led to another file, atoi.chf, which only used another library function, strtol(const char *str, char **endptr, int base), to make the conversion. The debugger, however, would not step into that function, so I could not find its source.

    Does anyone know if/where I can find the inner workings of these functions?

    Note: I'm using a C/C++ interpreter, Ch, on Windows 7. All of the files I found are within the C:\Ch directory.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    That code is usually pre-compiled and linked in a shared library by the time you get to use it so you cant jump to it unless you are prepared to read it in assembler.

    Try have a look at libc (GNU C Library - GNU Project - Free Software Foundation (FSF)), that has good implementations if you want to have a look at how the functions work

  3. #3
    Registered User
    Join Date
    May 2010
    Location
    San Jose, California, United States
    Posts
    22
    thanks for the quick response!
    hmm oh yea I remember about that now that you mention it - pre-processing -> compiling -> assembly -> linking

    well do you know where I can find the assembly file?

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    343
    Usually you add an option to the compiler command line to generate either a listing file or assembler output for the files you're compiling. This still won't show ASM code for the libraries. There you need a tool to disassemble the libraries - depending on lots of factors this can be easy or difficult to do. What are you using to compile - compiler, OS, and so on.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Quote Originally Posted by LanguidLegend View Post
    thanks for the quick response!
    hmm oh yea I remember about that now that you mention it - pre-processing -> compiling -> assembly -> linking

    well do you know where I can find the assembly file?
    Did you try libc? There are C versions of the functions you mentioned in the download

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by LanguidLegend View Post
    thanks for the quick response!
    hmm oh yea I remember about that now that you mention it - pre-processing -> compiling -> assembly -> linking

    well do you know where I can find the assembly file?
    If you're looking for library source code, most often it's not available except directly from the library's authors... and usually at a fee.

    There are "library like" source codes, as Fordy points out, that can be downloaded. But these will not be the exact source of your library.

  7. #7
    Registered User
    Join Date
    May 2010
    Location
    San Jose, California, United States
    Posts
    22
    Quote Originally Posted by Fordy View Post
    Did you try libc? There are C versions of the functions you mentioned in the download
    I tried looking on the GNU C Library website, but couldn't find a list of library functions. Could you link me to a list or just to the atoi function page?

    Thanks!

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz

    Download it...decompress it...look at what's inside

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by LanguidLegend View Post
    I tried looking on the GNU C Library website, but couldn't find a list of library functions. Could you link me to a list or just to the atoi function page?

    Thanks!
    The GNU C Library - GNU Project - Free Software Foundation (FSF)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Library Functions
    By gr8npwrfl in forum C++ Programming
    Replies: 0
    Last Post: 07-28-2008, 11:16 AM
  2. Gnu Scientific Library functions
    By zdream8 in forum C Programming
    Replies: 11
    Last Post: 06-09-2008, 09:37 AM
  3. Library functions
    By boucharafa in forum C Programming
    Replies: 8
    Last Post: 03-31-2007, 03:06 PM
  4. C++ standard library functions
    By eno in forum C++ Programming
    Replies: 1
    Last Post: 12-16-2003, 09:15 PM
  5. Location of member functions in memory
    By bennyandthejets in forum C++ Programming
    Replies: 4
    Last Post: 12-05-2003, 08:30 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21