Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Usually the problem of having possible multiple inclusions is solved with a series of #ifdef #ifndef but the pragmas just solves this with a single line, apparently they are really useful and can make the code better in terms of readability.

Why they are not part of the C++ and C standards? there is a better way to avoid multiple inclusions?

share|improve this question
You seems to be asking specifically about one use of #pragma, #pragma once. If that's the case you should change your question to make that explicit. – Winston Ewert Jul 3 '12 at 15:19
-1, you had time to read the comment, actually did it and did not react either. I remove the downvote after you have clarified the question. – Doc Brown Jul 3 '12 at 17:02

The very definition of #pragma is that they are non-Standard. Features which are provided as Standard are provided in some other way. Making #pragma Standard would defeat the purpose of, well, #pragma. They are nothing more than a set of implementation extensions, which happen to coincidentally be the same.

share|improve this answer
please see the my comment on the first answer. – user827992 Jul 3 '12 at 16:05
@user827992: What about it? – DeadMG Jul 3 '12 at 17:13

Because it is precisely targeted at specific compiler implementation therefore to support things that would not be part of the standards. Some compilers may elect to support conveniences such as you describe in their own way while others may not support them at all and still be standards compliant.

share|improve this answer
i don't get it; the entire C++ language depends on compiler implementations, also if you just consider for a moment a keyword like inline it' more a suggestion rather than a true command for the compiler; i do not think that you can guess the binary code that your source will generate before giving the "compile" command. I ask for the reason why they are not supported, i know that in today compilers they aren't, but what is the true reason. – user827992 Jul 3 '12 at 16:04
The C++ language does not depend on a compiler existing at all. – Otávio Décio Jul 3 '12 at 16:18
ok, explain to me how inline works if you say that language is "not dependant" from the compiler. – user827992 Jul 3 '12 at 16:20
inline is a C++ language keyword so any compiler will compile it. However it is totally up to the compiler implementation to honor it. Some compilers do, some don't and in this case the inline is simply ignored. – Otávio Décio Jul 3 '12 at 16:24
inline's purpose has nothing to do with inlining. It's about ODR and multiple function definitions. Whether or not the compiler actually inlines the code is completely irrelevant and orthogonal. – DeadMG Jul 3 '12 at 17:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.