All Questions
Tagged with pragma include-guards
14 questions
1
vote
0
answers
143
views
How to disable inclusion of header when using `#pragma once` (similiary to when using include guards)?
From time to time I have to retrofit unit testing into an unfriendly environment.
In these cases include guards are pretty useful, because:
I could suppress inclusion of unwanted header file,
I could ...
4
votes
3
answers
8k
views
#pragma once vs. include guards [duplicate]
I am going through Implementation defined behavior control
and there is the following text in relation to #pragma once:
Unlike header guards, this pragma makes it impossible to erroneously use the ...
0
votes
0
answers
61
views
pragma once or ifndef define endif [duplicate]
in header files we use pre-processor making an inclusion guards so in view of avoiding multiple header files inclusion so we write:
// mytest.h
#ifndef MY_TEST_H
#define MY_TEST_H
// code here
int ...
1
vote
1
answer
261
views
Why are there no include guards in Numerical Recipes header files?
novice C++ programmer here.
I'm using Numerical Recipes (V3) source code as part of a larger, modulated C++ project.
While I'll try not to get into the specifics of my problem, I am curious as to ...
0
votes
2
answers
393
views
Understanding headers and include
I am trying to grasp how actually multiple definitions of include files collaborate and sometimes collide. So I have a custom header file file.h, where some functions are declared within an #include ...
23
votes
1
answer
10k
views
How to make CLion use "#pragma once" instead of "ifndef ... def ..." by default for new header files?
By default, CLion will add the following lines to a newly created header file:
#ifndef SOME_NAME_H
#define SOME_NAME_H
.... your code here
#endif //SOME_NAME_H
But I like #pragma once more. How can ...
3
votes
2
answers
1k
views
Compiler does not support #pragma once
I have a compiler (PGI) that does not support
#pragma once
but the library (thrust) I would like to include uses them.
Is there a workaround for this problem?
6
votes
3
answers
8k
views
When to use include guards or #pragma once C++ [closed]
Is it good practice to use your choice of either/both include guards and #pragma once in every header file, or just those with something such as a class declaration?
I am tempted to put it in every ...
3
votes
2
answers
172
views
Since other abusable but useful features have been standardized, why not #pragma once?
The nonstandard #pragma once feature is implemented on practically all C++ compilers, but the C++ standard excludes it.
The usual explanation of why #pragma once, or some language construct that does ...
36
votes
3
answers
6k
views
Should I still use #include guards AND #pragma once?
http://en.wikipedia.org/wiki/Pragma_once
Should I still use include guards when all of these compilers support #pragma once?
A lot of responses on stack overflow say to use both for compatibility, but ...
5
votes
2
answers
999
views
Does "#pragma once" have the potential to cause errors?
All of my header files use include guards as well as pragma once:
#pragma once
#ifndef FILE_NAME_H
#define FILE_NAME_H
class foo
{
//foo interface..
};
#endif /* FILE_NAME_H */
I understand ...
5
votes
3
answers
4k
views
multiple definition and namespace
Is that the right way to have functions in namespace that i will #include in multiple files?
test.h
#pragma once
#ifndef TEST
#define TEST
namespace test{
namespace {
...
62
votes
9
answers
12k
views
Why isn't C/C++'s "#pragma once" an ISO standard?
I am currently working on a big project and maintaining all those include guards makes me crazy! Writing it by hand is frustrating waste of time. Although many editors can generate include guards this ...
444
votes
16
answers
256k
views
Is #pragma once a safe include guard?
I've read that there is some compiler optimization when using #pragma once which can result in faster compilation. I recognize that is non-standard, and thus could pose a cross-platform compatibility ...