Thread: Including headers in a header file

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    66

    Including headers in a header file

    Hi, where should you place #include's inside of a header file for "best practice" ?

    Ex:

    Code:
    // Header.h
    
    // #include here or below?
    
    #ifndef HEADER_H_
    #define HEADER_H_
    
    // #include here or above?
    
    // ...
    
    #endif HEADER_H_
    Or does it not matter at all?
    "When your work speaks for itself - don't interrupt!"

    -Samantha Ingraham.

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    If the headers you're including are also header-guarded it shouldn't matter, but they should be inder the header guards. So between the #define and #endif. If you think about it that part of the code will only be compiled once, and that's all you need/want.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    66
    Ah makes sense. Thanks! ^^
    "When your work speaks for itself - don't interrupt!"

    -Samantha Ingraham.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Also, if you do it the other way round, the include guard optimization that most compilers have doesn't kick in.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Including header file with in the header file
    By Arafat_211184 in forum C Programming
    Replies: 13
    Last Post: 12-19-2005, 10:03 AM
  3. Replies: 4
    Last Post: 12-14-2005, 02:21 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM