Traditionally, the standard and portable way to avoid multiple header inclusions in C++ was/is to use the #ifndef - #define - #endif
pre-compiler directives scheme also called macro-guard scheme (see code snippet below).
#ifndef MY_HEADER_HPP
#define MY_HEADER_HPP
...
#endif
In most implementations/compilers (see picture below) however, there's a more "elegant" alternative that serves the same purpose as the macro-guard scheme called #pragma once
. #pragma once
has several advantages compared to the macro-guard scheme, including less code, avoidance of name clashes, and sometimes improved compile speed.
Doing some research, I realized that although #pragma once
directive is supported by almost all known compilers, there's a turbidness on whether #pragma once
directive is part of the C++11 standard or not.
#pragma once
directive is part of the C++11 standard or not?#pragma once
).Definition of is (Entry 1 of 4) present tense third-person singular of be. dialectal present tense first-person and third-person singular of be. dialectal present tense plural of be.
Is is what is known as a state of being verb. State of being verbs do not express any specific activity or action but instead describe existence. The most common state of being verb is to be, along with its conjugations (is, am, are, was, were, being, been). As we can see, is is a conjugation of the verb be.
Definition of in use : being used All of the computers are currently in use.
Cambridge. / (ˈkeɪmbrɪdʒ) / noun. a city in E England, administrative centre of Cambridgeshire, on the River Cam: centred around the university, founded in the 12th century: electronics, biotechnology.
is. ( ɪz) vb. (used with: he, she, it, and with singular nouns) a form of the present tense (indicative mood) of be 1.
Synonyms for is. bears, lies, sits, stands. 3 to take or have a certain position within a group arranged in vertical classes. our school's football team is first in its division.
noun, plural I's or Is, i's or is. the ninth letter of the English alphabet, a vowel. any spoken sound represented by the letter I or i, as in big, nice, or ski. something having the shape of an I. a written or printed representation of the letter I or i. a device, as a printer's type, for reproducing the letter I ori.
“Was” is used for the indicative past tense of “to be,” and “were” is only used for the subjunctive past tense. as is. as 1 (def. 23). First recorded before 900; Middle English, Old English; cognate with Dutch is, Old Norse es, er, German, Gothic ist, Latin est, Greek estí, Old Church Slavonic jestĭ, Sanskrit asti
#pragma once
is not standard. It is a widespread (but not
universal) extension, which can be used
It was considered for standardization, but rejected because it cannot be implemented reliably. (The problems occur when you have files accessible through several different remote mounts.)
It's fairly easy to ensure that there are no include guard conflicts within a single development. For libraries, which may be used by many different developments, the obvious solution is to generate a lot of random characters for the include guard when you create it. (A good editor can be set up to do this for you whenever you open a new header.) But even without this, I've yet to encounter any problems with conflicts between libraries.
Section §16.6 of the Standard (N3936 draft) describes #pragma
directives as:
A preprocessing directive of the form
# pragma pp-tokensopt new-line
causes the implementation to behave in an implementation-defined manner. The behavior might cause translation to fail or cause the translator or the resulting program to behave in a non-conforming manner. Any pragma that is not recognized by the implementation is ignored.
Basically #pragma once
is an implementation specific instance of a #pragma
directive, and no, it's not standard. Yet.
It is often widely supported by most "major compilers" including GCC and Clang and is therefore sometimes recommended to avoid include-guards boilerplate.
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