Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Include Guards for Standard Headers

I am wondering if/ what include guards on files like windows.h, math.h, iostream, stdio... etc.

Since I have those headers included multiple times in different files. Do those files already have guards built in or is there a definition defined?

I am just wondering what the standards are for that kind of thing.

like image 285
Evan Carslake Avatar asked Nov 02 '13 03:11

Evan Carslake


1 Answers

The C++ standard requires that the headers be organized such that you can include any of them multiple times, directly or indirectly, without running into problems. It doesn't mandate how that result will be achieved, just that it shall be achieved.

ISO/IEC 14822:2011

17.6.2.2 Headers [using.headers]

¶2 A translation unit may include library headers in any order (Clause 2). Each may be included more than once, with no effect different from being included exactly once, except that the effect of including either <cassert> or <assert.h> depends each time on the lexically current definition of NDEBUG.178

178 This is the same as the Standard C library.

like image 191
Jonathan Leffler Avatar answered Sep 24 '22 02:09

Jonathan Leffler