By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,929 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,929 IT Pros & Developers. It's quick & easy.

header include order

P: n/a
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
Jun 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Marco Spatz" <ma******@web.de> skrev i meddelandet
news:5v************@icido.de...
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
Jun 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.