the source code for C header


Results 1 to 6 of 6

Thread: the source code for C header

  1. #1
    Join Date
    Jan 2001
    Location
    Jakarta,Indonesia
    Posts
    113

    the source code for C header

    hello all,

    I'm newbie in linux C programming. I just couldn't understand how this works :

    When i include xxx.h for example, when i view the content of xxx.h, it just contains constants or function name without the body, but i can using the function list in xxx.h, so where is the body of the function ?
    And what is the purpose of a C file that only contains int errno;

    thanks for reading and helping me...

    NOP
    Ada banyak hal menarik di sini.
    There are so many interests here.

  2. #2
    Join Date
    Jul 2000
    Location
    come from China
    Posts
    53
    I am not sure ,I think maybe it is following.

    There are directories :/include and /lib ,it seem that /include are head files which include the function prototype but the function bodies are in lib in the /lib.when you u compiling source file which include *.h ,compiler will extract the function from lib file.
    _SeReNe_

  3. #3
    Join Date
    May 1999
    Posts
    301
    They are stored in a library. The standard c library at least is stored in libc in most (if not all) UNIX.

    Code:
    And what is the purpose of a C file that only contains int errno;
    It defines the errno symbol. The header can only declare it as "extern int errno;" Well it can define it, but if it gets included by multiple C files, then you are going to have multiple definitions of errno and the linker will complain.

  4. #4
    Join Date
    Jan 2001
    Location
    Jakarta,Indonesia
    Posts
    113
    thanks,

    but if i want to know the function body, how do i get it ?
    And how the compiler know where to find the function body ? Or it just know how.


    thanks...
    NOP

    [ 17 October 2001: Message edited by: nopri ]
    Ada banyak hal menarik di sini.
    There are so many interests here.

  5. #5
    Join Date
    Dec 1999
    Location
    San Gabriel, CA, USA
    Posts
    615
    if you want to see the code for the functions just look at the source code for libc, gcc knows where to find the libs because of the linker program ld which has a file in /etc called ls.so.conf which contains the paths to the libs on your system, and yes gcc links using libc by default, if you want to do it manually which makes no difference add -lc to the commandline
    Welcome to Der Weinerschnitzel May I take your order please?
    Yeah, I want: Two large Cokes, Two large fries Chili-cheese dog, large Doctor Pepper Super deluxe, with cheese and tomato.
    You want Bill sperm with that?
    NO!
    -- The Descendents

  6. #6
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    And if you want to know where the source for libc can be gotten from, there are tarballs on the GNU Project's FTP site.

    However, I don't know the full path now, because the GNU server is full. There's a mirror that contains glibc source here -- get the newest glibc tarball, along with the one for Linux threads (the same version) if you want to look at threading code. Once they are downloaded, go into wherever you downloaded it to, and do a tar xzf <filename>.tar.gz -- replace <filename> with whatever you downloaded (hint: use tab-completion for the filename).

    This should create a directory that you can cd into and look at the source.

    [ 17 October 2001: Message edited by: bwkaz ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •