Answer the question
In order to leave comments, you need to log in
Why are #pragma once and header guards used together?
While studying the standard libraries in Visual Studio 2019, I was surprised by these lines:
// string standard header
#pragma once
#ifndef _STRING_
#define _STRING_
// vector standard header
#pragma once
#ifndef _VECTOR_
#define _VECTOR_
Answer the question
In order to leave comments, you need to log in
Thank you all for your help! Adamos correctly suggested - in " https://ru.wikipedia.org/wiki/Pragma_once " it says:
You can use both #pragma once and include guards to write portable code, which can also benefit from using #pragma once when optimizing (if the compiler supports it):
There's no advantage to use of both the include guard idiom and #pragma once in the same file.
Well, at least due to the fact that Pragma once is a non-standard directive, and the compiler is not required to support it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question