#pragma once
is not standard, but is supported by compilers like gcc and VC++. It helps to avoid inclusion guards.
But, internally, does the compiler add inclusion guards for #pragma once
? If not, how does the compiler ensure that such a header is included only once?
I'm sure it works just like include_once
in PHP - there is a table of "files that has been included". The compiler, in this case, looks in the list for the file it is about to include and if a file has already been included, don't include it again. If the compiler, while processign the file, sees a #pragma once
, then add this file to "files that have already been included".
So it's not the same as inclusion guards on a detail level, but it has the same effect as inclusion guards. It also makes the code less portable, since there are plenty of compilers that doesn't support this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With