Questions tagged [include-guards]

Anything related to C/C++ include guards technique, i.e. a technique employing C-preprocessor conditional compilation features in order to prevent multiple inclusion of header files in C/C++ source files.

Anything related to C/C++ include guards technique, i.e. a technique employing C-preprocessor conditional compilation features in order to prevent multiple inclusion of header files in C/C++ source files.

185 questions
4
votes
2 answers

C++ duplicate symbol linker error with proper include guards?

I'm writing a program to test concrete inheritance, though I cannot resolve the duplicate symbol linker error Clang returns. My understanding is duplicate symbols is always the result of incorrect includes/guards. I have triple checked my…
kits
  • 609
  • 6
  • 20
4
votes
2 answers

C Header include-guards used only in header files but not in .c files. Why?

I have been using guards in the header files for a while and the only reason I understand why they are used is to enable a single inclusion of this ( header file having guards under consideration ) while compilation. I want to know if there are any…
Adit Ya
  • 731
  • 1
  • 8
  • 19
3
votes
5 answers

Why to put the entire header content within guard tokens?

C and C++ distinguishes between declarations an definitions. You can declare a symbol many times, but you are allowed to define it only once. By learning this I have an idea to put declarations outside the guards, while definitions inside the…
Calmarius
  • 18,570
  • 18
  • 110
  • 157
3
votes
5 answers

C include guard

When file1.c includes inc.h (containing the include guard #ifndef INC_H) for the first time, the #define INC_H is performed. But now, when another file2.c includes the same inc.h, is the macro INC_H already defined, all it's the same story and…
Cartesius00
  • 23,584
  • 43
  • 124
  • 195
3
votes
4 answers

suppress gcc warnings : "warning: this is the location of the previous definition"

I need a set of wrappers around the standard system calls-open,listen,etc. For these i have a few "#define" as in: #define open(a,b,c) JCL_Open(a,b,c) But when i compile the header and associated .c files, i am getting the following…
maximus1986
  • 179
  • 3
  • 3
  • 7
3
votes
3 answers

Double include solution?

In C++, I have a problem with a double include: File stuffcollection.h #pragma once #ifndef STUFFCOLLECTION_H #define STUFFCOLLECTION_H #include "Stage.h" class Stuffcollection { public: bool myfunc( Stage * stage ); }; #endif //…
Ben
  • 15,938
  • 19
  • 92
  • 138
3
votes
0 answers

Send Password Reset Email through different Guards

I have 4 different guards registered in my auth.php file. I have a single page for resetting the password for users in the four guards. So, while sending the email I manage to figure out which guard to use by sending it through the form. My…
Advaith
  • 2,490
  • 3
  • 21
  • 36
3
votes
0 answers

Avoid multiple macro unfolding for same input

I want my macro to be only unfolded once for each possible argument. #define PAX_CREATE_MEMBER_CHECKER_FOR_NAME(memberName) \ template \ struct HasMember_##memberName : std::false_type { }; \ …
3
votes
4 answers

What are actual use cases for double header inclusion in C?

Inclusion guards (as well as the #pragma once) in C header files are frequently used and well described in a wikipedia article and a way to prevent mistakingly double include a header file. This questions asks in which cases it would be desired, in…
humanityANDpeace
  • 4,350
  • 3
  • 37
  • 63
3
votes
1 answer

Error "not declared in the scope" but with interfaces

You see I've been trying to create a std::vector which contains the Entity class inside the IState class. Both classes are interfaces. The error is 'Entity' was not declared in this scope and it points to : protected: std::vector
Jackoz
  • 41
  • 7
3
votes
3 answers

#include guard doesn't work - or I don't understand it

I work with several files: main.c assembler.c fileHandlers.c handlers.c in addition I have several header files, containing constants, function prototypes etc. In one of them ("datatypes.h") I defined an array of strings: #ifndef DATATYPES_H #define…
Elad Edri
  • 331
  • 2
  • 9
3
votes
2 answers

Inclusion problem

I have an inclusion pattern as follows: /* * Class1.h */ #ifndef CLASS1_H_ #define CLASS1_H_ #include "Class2.h" namespace Class1_namespace { class Class1 { Class2* Class2_ptr; void Class1_member() { (*Class2_ptr).Class2_method(); …
user383352
  • 5,033
  • 4
  • 25
  • 20
3
votes
2 answers

Include statements outside include guards

I recently started working on a project where I came across this: #include // includes before include guards #include "whatever.h" #ifndef CLASSNAME_H // header guards #define CLASSNAME_H // The code #endif My question: Considering all…
pianoslum
  • 327
  • 3
  • 9
3
votes
2 answers

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?
user1928546
  • 143
  • 1
  • 1
  • 5
3
votes
2 answers

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 what #pragma once does, has been excluded from…
thb
  • 13,796
  • 3
  • 40
  • 68