I dimly remember a rule that "No header of the C standard library shall include any other header of the C standard library, except where specifically allowed". But curiously, I couldn't find such a rule written down in C11. I would have expected it in 7.1.2 "Standard headers".
- Is there such a rule in C?
- Is there such a rule in POSIX?
- Is there such a rule in any other standard?
There is no such rule in the C language specification or the POSIX standards. Both of these, especially the first, steer well clear of specifying implementation details such as this. They describe positive structure and semantics that users can rely on, but generally do not constrain implementations to avoid specific structures or details.
For the most part, the standards also do not specify that any particular headers do include other header, so, as a matter of style and portability, it is wise to write code as if no standard header included any other. More generally, this leads toward a common style guideling that each source file you write, including headers, should, for each identifier used, either declare that identifier appropriately itself or
#include
a header documented to declare it.However, as @chqrlie points out in their answer, the standard explicitly specifies that certain standard library headers include specific other standard library headers.
That is indeed where one would look in C11. As you say, it expresses no rule having the effect you describe.
No, and that would be inconsistent with other provisions, as described above. Furthermore, in some putatively conforming C implementations, more of the standard headers than those @chqrlie points out do
#include
other standard library headers.No, and that would be inconsistent with other provisions, as described above. Furthermore, in some putatively POSIX-conforming C implementations, more standard headers than those @chqrlie points out do
#include
other standard library headers.I am unaware of any other standard that speaks to the C standard library. There is a wide variety of code conventions, and it is conceivable that one or more have such a rule about writing program and library headers, but the standard library is not within the scope of such conventions. Obviously, however, no one can speak authoritatively about the universe of all standards.
It is perhaps relevant also to raise paragraph 7.1.2/4 of C11, which says, in part:
The C language specification explicitly disclaims any requirement that the standard library headers be implemented as ordinary source files expressed in the C language, but do note that to the extent that a particular implementation provides such a representation, that explicitly raises the possibility that some identifiers may be declared or defined by multiple headers. Although it is not guaranteed to happen, and there are other ways that could arise, it is consistent with some headers including others.