Double header guards in Visual Studio stl numeric implementation

49 Views Asked by At

In the stl implementation that comes along with Visual Studio 12.0 the numeric header looks like this

#pragma once
#ifndef _NUMERIC_
#define _NUMERIC_

// shortened for the sake of readibility
. 
.
.


#endif /* _NUMERIC_ */

I know that #pragma once is not standard conform.

Nevertheless, why did they implement a double header guard?

1

There are 1 best solutions below

0
Jeaninez - MSFT On

#pragma once: The same file will not be included multiple times include guard idiom:uses preprocessor macro definitions to prevent multiple inclusions of the contents of the file.

According to the Doc

There's no advantage to use of both the include guard idiom and #pragma once in the same file. The compiler recognizes the include guard idiom, and implements the multiple-include optimization the same way as the #pragma once directive if no non-comment code or preprocessor directive comes before or after the standard form of the idiom

I suggest you could refer to the link:https://stackoverflow.com/a/13339535/11872808