Thread: libraries

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    28

    libraries

    OK, I made it through a c programming book and now I am embarking on my first real program, nothing to advanced though I am just going to try and make a monopoly game. I figure if I can do that then I have a pretty good understanding of the basics of c programming.
    Thinking ahead though, I am curious about all the c libraries. C is supposed to be a portible language so If I write a simple hello world program only including <stdio.h> on machine A then If I want to run that same program on Machine B, linux for example, then I would have to recompile my soucre code on a compiler under linux right?
    And if its just a simple hello world program then nothing should have to be changed in the source code correct. What is the difference between the stdio.h on machine A and machine B? Or are they the same but other libraries are linked to the hello world program that are machine dependent?
    My next question is one that confuses me the most. All the basic functions of c are prototyped in headers but defined elswhere correct? So If you wanted to write a program without using anyone else's code (re-inventing the wheel) how would you do that? Say I wanted to print a character to the screen and not you printf or puts or putchar or any other function you can think of. Would I have to use a pointer to put stuff directly in video memory? Or is the c language defined by its include library's. I hope I am making since here cause I am confusing myself trying to ask my questions. Thanks for any answers

    Vertex34

  2. #2
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    yes the libraries are linked to different objects on different machines ex: linux is glibc. To rewrite certain functionst that require i/o devices you must go into assembly. C has nothing to do with i/o at all. Most string functions can be rewritten for practice though.

  3. #3
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    The binary would work only if the libraries were the same, the source, if it follows the standards, should be compilable on anything that says it supports C.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  4. #4
    Quote Originally Posted by Vertex34
    Thinking ahead though, I am curious about all the c libraries. C is supposed to be a portible language so If I write a simple hello world program only including <stdio.h> on machine A then If I want to run that same program on Machine B, linux for example, then I would have to recompile my soucre code on a compiler under linux right?
    Right, as long as the code is using conforming C and standard C library functions.
    And if its just a simple hello world program then nothing should have to be changed in the source code correct.
    Correct.
    What is the difference between the stdio.h on machine A and machine B?
    The answer is beyond the definition of the C-language. It's an implementation issue.

    The contain of the header files doen't need to be portable or conforming at all. Can be anything. Only the result counts.
    Or are they the same but other libraries are linked to the hello world program that are machine dependent?
    Some parts of the libraries bodies are written in standard C, others in implementation-dependent C, or other languages like assembly for example (could be Pascal or whatever). Only the interface and the behaviour have to be conforming.
    My next question is one that confuses me the most. All the basic functions of c are prototyped in headers but defined elswhere correct?
    Correct.
    So If you wanted to write a program without using anyone else's code (re-inventing the wheel) how would you do that? Say I wanted to print a character to the screen and not you printf or puts or putchar or any other function you can think of.
    Yes, you can do that. You will have to use some extensions from your compiler that allow low level system calls or direct memory and / or hardware access. Of course, don't expect the code to be portable. (Keep in mind that the system may allow or not such accesses and that the hardware details may change from a machine to another).
    Would I have to use a pointer to put stuff directly in video memory?
    It depends on the target. Such a stuff may have sense of not. It's definitely not a C-issue.
    Or is the c language defined by its include library's.
    The core of the C-language is defined by its syntax and semantics on one hand, and by its library of functions on the other hand. Note that only the interfaces and the behaviours of the library functions are defined.
    Last edited by Emmanuel Delaha; 07-18-2004 at 12:57 AM. Reason: Typos
    Emmanuel Delahaye

    "C is a sharp tool"

  5. #5
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    Would I have to use a pointer to put stuff directly in video memory?
    You cannot do this in Linux, the kernel is considered safe and will not you allow you to do this. you have to compile a kernel module.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    So If you wanted to write a program without using anyone else's code (re-inventing the wheel) how would you do that? Say I wanted to print a character to the screen and not you printf or puts or putchar or any other function you can think of.
    Here's a brief and incomplete history of computer languags. Binary is a human readable representation of the electrical signals that get sent through a circuit. Assembly is just a literal translation of binary. You can replace every part of assembly code with a preset combination of 1's and 0's. Sounds like you want assembly.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    28
    Yeah i have spent many hours learning some of the basics of assembly and have even gotten as far as writing a bootloader and bootstrap program nothing to fancy though. the computer would load up and say loading bootloader then loading bootstrap then it would say system halted. I put my study of assembly on hold to learn more about c programming. I understand a lot of the more advanced topics on how the cpu works but there are a lot of other things that don't make sense to me yet. For the most part I guess because i switch between topics of study to often instead of staying with the same topic steadily. But Now I am going to stay commited to studying c then once I understand all I want to know I will start trying to optimize my programming skills with assembly.

    thanks for all of your guys input on my questions. I checked I book out from the library today that covers the standard c libraries so hopefully that will help me out a lot.

    Vertex34

  8. #8
    Quote Originally Posted by Vertex34
    Yeah i have spent many hours learning some of the basics of assembly <...> Now I am going to stay commited to studying c then once I understand all I want to know I will start trying to optimize my programming skills with assembly.
    Actually, deep assembly skills are not necessary to write most application level programs in C-language, at last on a hosted target (could be another story with system-level programming like writing a driver, or on stand-alone targets like most embedded systems).

    The purpose of a high-level-language (even if C is probably the lowest level high-level-language) is precisely to supply an abstraction layer that ignores the machine details.

    A basic knowledge of the machine/assembly language of the machine you write code for, can be helpful to understand some detailed step to step debugging processes.

    Compilers are rather good at writing assembly code (this is what they are maid for, at least for a part called 'back-end'). You can try to beat them, but don't dream too much if you fight against modern compilers like Microsoft VC++6, Borland BCB, gcc 3.x etc, specially if you activate the optimization options (and don't be surprised if can't read the produced assembly code anymore!)

    That said, if you are an expert in assembly for a peculiar target, you can use these skills to write the back-end of a compiler for it.
    Emmanuel Delahaye

    "C is a sharp tool"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC: Compiling with both static and shared libraries
    By eatwithaspork in forum C Programming
    Replies: 4
    Last Post: 06-23-2008, 01:48 PM
  2. Replies: 7
    Last Post: 05-13-2008, 03:47 AM
  3. MinGW thread-safe runtime libraries
    By Mario F. in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2006, 08:15 AM
  4. Libraries and headers
    By darksaidin in forum C++ Programming
    Replies: 10
    Last Post: 07-23-2003, 06:24 AM
  5. QT and external libraries
    By Quacker in forum Linux Programming
    Replies: 1
    Last Post: 04-08-2003, 07:02 AM