Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is requiring a certain order for #includes in c++ a sign of bad library/header design?

I've used some very large scale systems and never seen a required order, but came across it recently. Does the STL or STD library or even Boost have any cases where certain includes must come in a certain order?

like image 641
ApplePieIsGood Avatar asked Dec 17 '08 19:12

ApplePieIsGood


People also ask

What is short detention order?

(v) SHORT DETENTION ORDER If a Short Detention Order (SDO) is made, the offender can be detained in prison for a period not exceeding 14 days.

Who is relevant person MCA?

(1) “Relevant persons” are persons who have an involvement in P's life and/or who are likely to have an interest in the application.

What is Criminal Procedure Code Singapore?

First introduced by the Legislative Council of the Colony of Singapore, the Criminal Procedure Code is a set of laws imperative for the management of a fair trial where rights of the accused are not compromised in any way.


2 Answers

Does the STL or STD library or even Boost have any cases where certain includes must come in a certain order?

For the standard, the answer is emphatically, no. I imagine the same is true for Boost, though I haven't looked it up.

From the C standard:

Standard headers may be included in any order; each may be included more than once in a given scope, with no effect different from being included only once, except that the effect of including <assert.h> depends on the definition of NDEBUG (see 7.2).

the C++ standard has similar wording.

My preference is that headers should include their own dependencies, but I've worked with people who believe this to be 'wasteful'. In my opinion, not having headers include their dependencies is a worthless early optimization.

like image 56
Michael Burr Avatar answered Nov 11 '22 17:11

Michael Burr


This definitely sounds like a bad design. If somehow a specific order was required, the library should provide one header that includes the other ones in the correct order.

As far as boost, and the STL, I'm pretty sure I haven't encountered this situation yet.

like image 21
Flame Avatar answered Nov 11 '22 19:11

Flame