Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a C implementation implicitly include standard headers when including a different header?

Tags:

c

header

c99

While reading Is this proper C declaration? If so, why does it not work? I was thinking about

#include <stdio.h>

int main(void) {
  int bool = 0;
  return bool == 0;
}

Is this program strictly conforming? In other words, is stdio.h allowed to include stdbool.h or is it forbidden to do so? Is this specified by the spec?

like image 808
Johannes Schaub - litb Avatar asked Jul 14 '11 14:07

Johannes Schaub - litb


People also ask

Should include statements be in the header files?

Your #include s should be of header files, and each file (source or header) should #include the header files it needs. Header files should #include the minimum header files necessary, and source files should also, though it's not as important for source files.

Where to put include files c++?

As a rule, put your includes in the . cpp files when you can, and only in the . h files when that is not possible. You can use forward declarations to remove the need to include headers from other headers in many cases: this can help reduce compilation time which can become a big issue as your project grows.


1 Answers

C standard headers can not include other headers. This is different from C++, where it is explicitly allowed.

C99 standard, section 7.1.3

Each header declares or defines all identifiers listed in its associated subclause[...] No other identifiers are reserved.

like image 132
Bo Persson Avatar answered Sep 28 '22 08:09

Bo Persson