header include order

M

Marco Spatz

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
 
B

Bo Persson

Marco Spatz said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top