C ++ Enable Protection for Standard Headers

I am wondering, whether the / it remedies files such as windows.h, math.h, iostream, stdio... etc.

Since I have these headers included several times in different files. Are security features already built into these files or is a definition defined?

I'm just wondering what are the standards for this kind of thing.

+6
source share
4 answers

If you open the file to read the contents (you can even right-click the include directive in most editors to open the file), you will see that the included files usually start with something like:

#ifndef _WINDOWS_
#define _WINDOWS_
...

, _WINDOWS_ , _WINDOWS_ , . #ifndef , .

, , , - #pragma once #pragma once. , - , .

+11

++ , , , , . , , .

ISO/IEC 14822: 2011

17.6.2.2 [using.headers]

¶2 ( 2). , - , , , ​​ , <cassert> <assert.h> NDEBUG. 178

178 , Standard C.

+11

#pragma once. #pragma once, . , . , (Visual Studio/Eclipse), . .

+3

/usr/include/ ( , debian). /usr/include/stdio.h

,

#ifndef _STDIO_H
# define _STDIO_H       1

cpp, grep __cplusplus,

#if !defined __cplusplus || defined __STDC_LIMIT_MACROS

...

+1

All Articles