header include order

Discussion in 'C++' started by Marco Spatz, Jun 29, 2006.

  1. Marco Spatz

    Marco Spatz Guest

    Hi,

    I used PCLint to check my code yesterday and got some warnings about
    "Repeated include files" and "Redundant declaration for symbol
    'CLASSNAME'". I know the reasons for these warnings and I think they are
    not a problem. But all this made me think about the order in which
    header files are include.

    Think about a 4 layered architecture with

    layer GUI (contains GUI_A,h, ...)

    layer APP (contains APP_A.h, ...)

    layer CORE (contains CORE_A.h, CORE_B.h, CORE_C.h ... you get it)

    layer STL (contains vector, set, ...)

    and a top-bottom dependency.

    Now let's say class GUI_A needs APP_A.h, CORE_A.h, and vector to be
    included in it's header. What would be the correct order to include it?
    Starting at the bottom or at the top?


    And further, class GUI_A needs GUI_A.h, APP_B.h, CORE_B.h and set in
    it's source to compile. Should this be in the same order as in the
    header file?


    Does the standard say something about it? Or are the any guidelines for
    this?

    Thanks in advance,

    Marco
     
    Marco Spatz, Jun 29, 2006
    #1
    1. Advertising

  2. Marco Spatz

    Bo Persson Guest

    "Marco Spatz" <> skrev i meddelandet
    news:...
    > Hi,
    >
    > I used PCLint to check my code yesterday and got some warnings about
    > "Repeated include files" and "Redundant declaration for symbol
    > 'CLASSNAME'". I know the reasons for these warnings and I think they
    > are
    > not a problem. But all this made me think about the order in which
    > header files are include.
    >
    > Think about a 4 layered architecture with
    >
    > layer GUI (contains GUI_A,h, ...)
    >
    > layer APP (contains APP_A.h, ...)
    >
    > layer CORE (contains CORE_A.h, CORE_B.h, CORE_C.h ... you get it)
    >
    > layer STL (contains vector, set, ...)
    >
    > and a top-bottom dependency.
    >
    > Now let's say class GUI_A needs APP_A.h, CORE_A.h, and vector to be
    > included in it's header. What would be the correct order to include
    > it?
    > Starting at the bottom or at the top?


    It shouldn't matter. :)

    >
    >
    > And further, class GUI_A needs GUI_A.h, APP_B.h, CORE_B.h and set in
    > it's source to compile. Should this be in the same order as in the
    > header file?
    >
    >
    > Does the standard say something about it? Or are the any guidelines
    > for
    > this?


    The guideline is that each header should include everything it needs.

    You can use include guards #ifdef ... #endif in the headers, to avoid
    defining the same symbol more than once.


    Bo Persson
     
    Bo Persson, Jun 29, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Soren Kuula
    Replies:
    2
    Views:
    529
    Soren Kuula
    Feb 1, 2004
  2. Aguilar, James
    Replies:
    2
    Views:
    718
    Aguilar, James
    Jul 16, 2004
  3. Derrick Coetzee

    Header include order

    Derrick Coetzee, Nov 19, 2003, in forum: C Programming
    Replies:
    69
    Views:
    7,174
    Randy Howard
    Nov 26, 2003
  4. Andreas Bogenberger
    Replies:
    3
    Views:
    974
    Andreas Bogenberger
    Feb 22, 2008
  5. mlt
    Replies:
    2
    Views:
    892
    Jean-Marc Bourguet
    Jan 31, 2009
Loading...

Share This Page