Thread: stdio.c???

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    stdio.c???

    Hi guys,

    I normally include the header of stdio.h to get some functions like printf() and so on. Ok, well so what's going on in the process of producing my outputfile, let's say a.out?

    I learned that the cpp comes first and cleans up the things with # (#include, #define,...), then there comes the gcc and it creates an assembler format with is then transformed into an object code like *.o. After that the linker/loader cleans up all problems like linking and referencing stuff.

    So that's what I know...not much but a bit .

    Anyways I was wondering where the function let's say printf() is hiding? Is there any stdio.c or is the all done with dynamic libraries and shared objects? And well if that's the case in with *.so is the function printf()??

    Oh, yeah I know how to check for dynamic linked libraries in a file (with ldd) and this gives my (I just included sdtio.h) the files

    linux-gate.so.1 => (0xffffe000)
    libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7da8000)
    /lib/ld-linux.so.2 (0xb7f03000)

    Mhm, maybe there's someone out there who did actually understand my question and might help.

    BTW: The problem came up because for math.h you always have to tell gcc with the -l obtions to get those functions. Why is this necessary for math.h but not for stdio.h??

    Thanks
    TurboToJo

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by DJTurboToJo View Post
    I learned that the cpp comes first and cleans up the things with # (#include, #define,...), then there comes the gcc and it creates an assembler format with is then transformed into an object code like *.o. After that the linker/loader cleans up all problems like linking and referencing stuff.
    What's cpp?
    For the rest, this is not true.
    The preprocessor runs first, and takes care of any preprocessor lines such as #include.
    Then the compiler runs, generates assembly and puts it into object files (*.o, *.obj, etc).
    Then the linker fixes up functions calls, etc, and pieces the files together into an executable.

    Anyways I was wondering where the function let's say printf() is hiding? Is there any stdio.c or is the all done with dynamic libraries and shared objects? And well if that's the case in with *.so is the function printf()??
    Typically, in libraries. DLLs for Windows and whatever library is for Linux.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    cpp is "c preprocessor" available for example on linux... gcc is "gnu c compiler"

    so your "not true" is not so true
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    About the preprocessor perhaps. But the general principle about the rest was still somewhat untrue.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Well, maybe that's why I was asking. Then let's try it again

    I could create my own dynamic libraries. First I need a code for example in function.c. There is the function func(). Then I create a shared object with

    gcc -shared -o libfunc.so function.c

    In main.c I just include the header "func.h" in which I declare the function func(). But there's no code for it in there! Ok, and now I compile my main.c with (let's assume I already set my LD_LIBRARY_PATH so that it looks for the func.h in the current directory .)

    gcc main.c -L . -lfunc


    This would create an a.out which would run.


    So and here's my question now. I think someone put all the code from a stdio.c in some dynamic library (maybe libc.so) and if you include stdio.h it get the code from this libc.so. Is that true?? And what about changes in the header stdio.h if I change something, maybe a new function is introduced and it will be declared in stdio.h. Who's gonna create a new libc.so? Because as far as I think in this libc.so aren't only the functions from stdio.h but also others from stdlib.h?

    So, what about this try???

    Thanks
    TurboToJo

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by DJTurboToJo View Post
    So and here's my question now. I think someone put all the code from a stdio.c in some dynamic library (maybe libc.so) and if you include stdio.h it get the code from this libc.so. Is that true??
    libc.so is in fact the C library, and it's always linked, whether you #include a header or not. The header files are irrelevant to linking.

    And what about changes in the header stdio.h if I change something, maybe a new function is introduced and it will be declared in stdio.h. Who's gonna create a new libc.so?
    Changing a standard header file is madness. If you did it, you'd have to recompile the C library from scratch. There's absolutely no reason to want to add functions to the C library, when you can just make your own library.

    Because as far as I think in this libc.so aren't only the functions from stdio.h but others from stdlib.h?
    Every single standard C function comes from libc. The header files have nothing to do with it. There is only a single library.

  7. #7
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    ...alright!

    thanks to all of you
    TurboToJo

Popular pages Recent additions subscribe to a feed