Thread: Making my own library

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    1

    Red face Making my own library

    I'm new to programming and I would like to write my own library to print integers without using standard library calls. How would I go about doing this?

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    So vague, and bold for somebody new to programming. Not using the standard library calls is going to make your life very difficult and your program very system dependent. If you can follow the entire post here, and think it should be pretty easy, then go for it. Otherwise, you may want to rethink your approach. Nothing wrong with writing wrappers around the standard library functions if your sole purpose is to learn how to make libraries, but if you really are quite new, I suggest you start with some basic tutorials that revolve around single-file programs. We have a few here on this site.

    This is a bit oversimplified:
    Generally, a library is compiled into a file that sits somewhere on your system. When you write a program that uses that library, you include the right headers and link it in during the linking stage of your build. How to do this depends on your compiler/linker.

    As for the actual library design, making a truly good library is something of an art, but at the very least you would need to start with a list of function you want to provide, and their return types and parameters. Then start writing them in small chunks, testing as you go. Make a header file that contains every symbol you would might need when using that library. This would include function prototypes, extern'ed variables, typedefs, enums, #defines and include guards. Place it in the appropriate location for include files on your system. Compile this into a statically or dynamically linkable library file (system/compiler dependent) and place it in the right location for libraries on your system and you're good to go.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    If this is just for fun, as in an exercise, you would have to write wrappers for the standard library functions, but you can't escape using the standard library altogether, so it seems like an exercise in futility to me.

    If you are trying to adapt the language to what you would want it to look like, then you are better off learning it first and making judgements about it later.
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-05-2010, 09:06 AM
  2. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  3. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  4. Making Static Library Files
    By fh791 in forum C++ Programming
    Replies: 2
    Last Post: 09-14-2004, 07:06 AM
  5. Making Library
    By Anglos in forum C Programming
    Replies: 7
    Last Post: 04-14-2002, 12:38 PM

Tags for this Thread