Necessary to include header files?

This is a discussion on Necessary to include header files? within the C Programming forums, part of the General Programming Boards category; Hi, Is it necessary to include header files at the top? Coz i tried not including the ctype.h and string.h ...

  1. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    Necessary to include header files?

    Hi,

    Is it necessary to include header files at the top? Coz i tried not including the ctype.h and string.h and still use their functions with success.

    thnx

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    65
    Well, in some compilers, not including header files sometimes works for frequently used functions. But always include the necessary header files as a good programming practice.
    The experimenter who does not know what he is looking for will not understand what he finds.
    - Claude Bernard

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    i asked this question because i am currently up the the character and strings part and i got mixed up with which functions in the string.h and which are in the ctype.h ?

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    Always include header-files, just like ozgulker said. If you don't, than it can happen that some compiler won't compile your code because it can't find some definitions.

    The header-files are stored in some include-directory. There you can find them and read them.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > Is it necessary to include header files at the top?
    It is only strictly necessary to include a file at some point before your first use of some declaration inside that file.

    So theoretically, you could have them spread thoughout the code.

    However, one of the things which is useful to be able to do is work out which files a particular module is dependent upon (for say porting to another platform). This is much easier to do if all the includes are together at the start of a file, and much harder if they are scattered.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    One important thing to note is that just because my compiler automatically includes stdio and stdlib when I compile doesn't mean that yours does. Keep in mind that you will probably use more than one compiler in your life time, so it is generally a good idea to make code that anyone can compile.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. where to include header files?
    By kaos_frack in forum C++ Programming
    Replies: 6
    Last Post: 12-30-2008, 02:09 PM
  2. Header files
    By GaPe in forum C Programming
    Replies: 6
    Last Post: 02-01-2003, 02:39 PM
  3. Header files
    By Jez_Master in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2002, 07:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21