Thread: difference between header and library

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    94

    Unhappy difference between header and library

    please explain... thanks

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    A header is just one file containing definitions and such whereas a library is a collection of header files and source files that ultimately provide a useful framework. For example, a data structure library could contain headers and source files that implement common data structures like trees, lists, etc. This library could then be used to produce useful programs faster (by reducing the time it takes to code those things provided in the library).
    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.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    94
    ok... but this means C programming language has one library? C standard library - Wikipedia, the free encyclopedia or? who are other types of libraries of C

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Yes, C standard library refers to all the functionality provided as part of the standard. You can search Google for other libraries. There are all sorts of libraries for developing GUIs, for scientific and mathematical computation, etc.
    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.

  5. #5
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Quote Originally Posted by claudiu View Post
    A header is just one file containing definitions and such whereas a library is a collection of header files and source files that ultimately provide a useful framework. For example, a data structure library could contain headers and source files that implement common data structures like trees, lists, etc. This library could then be used to produce useful programs faster (by reducing the time it takes to code those things provided in the library).
    I believe a header should include:

    #includes needed for that specific header
    #defines and macros
    constants
    structs
    enums
    function declarations (not definitions)

    Function declarations belong in a file of the same name as the header, but with a .c extension. Also the program should be compiled separately and linked together later. Correct me if I am wrong...

  6. #6
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Function declarations belong in a file of the same name as the header, but with a .c extension
    Not a requirement. .

  7. #7
    Registered User \007's Avatar
    Join Date
    Dec 2010
    Posts
    179
    Not required, but good practice.

    More on headers:

    Header Files - The C Preprocessor

  8. #8
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Header files are just C source (text) files containing function prototypes, defines, compiler directives. They are #included in your source files as needed. Usually have extension .h Libraries are already compiled objects (code) which are linked together with your code. Extension .lib. Standard library is implied without any additional fuss but if you wish to incorporate other external libraries the "environment" must be told to include them. Or they are named in make files.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    To understand the difference between header and library; it helps to know the difference between Compiler and Linker. The two areas really go together.

    Tim S.

  10. #10
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by \007 View Post
    I believe a header should include:

    #includes needed for that specific header
    #defines and macros
    constants
    structs
    enums
    function declarations (not definitions)

    Function declarations belong in a file of the same name as the header, but with a .c extension. Also the program should be compiled separately and linked together later. Correct me if I am wrong...
    Like Bayint pointed out it really depends on what you are actually doing. I used definitions in the more general sense (and perhaps, granted, it was a poor choice of words) not in the C sense of definitions vs declarations.
    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. Need Help With Header library file..
    By kensam in forum C Programming
    Replies: 8
    Last Post: 01-27-2010, 01:39 PM
  2. include library header in header files
    By Raison in forum C++ Programming
    Replies: 6
    Last Post: 09-27-2004, 02:50 AM
  3. Header and Library Files
    By jrahhali in forum C++ Programming
    Replies: 9
    Last Post: 08-23-2004, 03:51 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Gnu C++ Library Header file question?
    By xddxogm3 in forum C++ Programming
    Replies: 13
    Last Post: 10-01-2003, 03:48 PM