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
19
votes
3 answers

Why can std::max and std::min still be used even if I didn't #include ?

#include int main() { int value1 = 1, value2 = 10; std::cout << "Min = " << std::min(value1,value2) <
Anthony
  • 409
  • 1
  • 5
  • 10
18
votes
2 answers

Which comes first? header guards, namespace and includes

I have been making files like this for awhile: Does the order make sense? or should the namespace and the #includes be swapped and why. #ifndef CLASSNAME_H // header guards #define CLASSNAME_H #include "a.h" // includes in alphabetical…
aCuria
  • 6,935
  • 14
  • 53
  • 89
16
votes
1 answer

Clang-Tidy llvm-header-guard directory configuration

Is there a way to remove the suggested computer specific path on the suggested llvm-header-guard string when running static analysis with clang-tidy? For example the suggested header guard for the file (cls/math/matrix.hpp) is: …
user7119460
  • 1,451
  • 10
  • 20
15
votes
2 answers

Customizing include-guard for Eclipse CDT

I want an automatically generated include-guard by creating a new C++-class with Eclipse/CDT, but I don't find any way to change the ${include_guard_symbol} attribute. My wish is an include-guard with a namespace prefix like following: #ifndef…
Dudero
  • 607
  • 7
  • 15
15
votes
2 answers

Template (.tpp) file include guards

When writing templated classes, I like to move the implementation into a different file (myclass.tpp) and include it at the bottom of the main header (myclass.hpp). My Question is: do I need include guards in the .tpp file or is it sufficient to…
perivesta
  • 3,417
  • 1
  • 10
  • 25
15
votes
2 answers

Eclipse-CDT: Use Namespace in automatic generated include-guards

Is it possible (and how) to add the namespace in the name of the automatic generated include guards in Eclipse CDT, when creating a new class using the .hpp/.cpp templates? For me Eclipse generates a new class with a namespace nicely, but the…
IanH
  • 3,968
  • 2
  • 23
  • 26
15
votes
2 answers

Purpose of Header guards

In C++ what is the purpose of header guard in C++ program. From net i found that is for preventing including files again and again but how do header guard guarantee this.
ckv
  • 10,539
  • 20
  • 100
  • 144
14
votes
4 answers

How to change C++ include guards in CLion?

When CLion creates a header file it adds include guard strings like this: #ifndef PROJECTNAME_FILENAME_H #define PROJECTNAME_FILENAME_H /* ... code ... */ #endif //PROJECTNAME_FILENAME_H But I want just FILENAME_H without the PROJECTNAME_ prefix.…
Kroll
  • 649
  • 2
  • 6
  • 17
14
votes
3 answers

Is an #include before #ifdef/#define Include-Guard okay?

I always placed my #include after the #ifdef/#define Include-Guard. Now the refactor mechanism of my IDE (Qt Creator) put it before the Include-Guard e.g. #include "AnotherHeader.h" #ifndef MYHEADER_H #define MYHEADER_H Can this cause any…
avb
  • 1,701
  • 5
  • 22
  • 37
12
votes
3 answers

Difference between pragma once inside and outside include guards?

Is there any difference between placing the #pragma once inside the include guards as opposed to outside? case 1: #ifndef SOME_HEADER_H #define SOME_HEADER_H #pragma once case 2: #pragma once #ifndef SOME_HEADER_H #define SOME_HEADER_H I'm just…
Marlon
  • 19,924
  • 12
  • 70
  • 101
12
votes
11 answers

C header file loops

I have a couple of header files, which boil down to: tree.h: #include "element.h" typedef struct tree_ { struct *tree_ first_child; struct *tree_ next_sibling; int tag; element *obj; .... } tree; and element.h: #include…
Scooby
  • 755
  • 2
  • 7
  • 9
12
votes
4 answers

Difference Between includes and imports

Possible Duplicate: What is the difference between #import and #include in Objective-C? What is the difference between #include< > #include" " #import< > #import" "
Gugan
  • 1,625
  • 2
  • 27
  • 65
11
votes
6 answers

Is there any situation where you wouldn't want include guards?

I know why include guards exist, and that #pragma once is not standard and thus not supported by all compilers etc. My question is of a different kind: Is there any sensible reason to ever not have them? I've yet to come across a situation where…
Mephane
  • 1,984
  • 11
  • 18
10
votes
4 answers

Is there any mechanism in Shell script alike "include guard" in C++?

let's see an example: in my main.sh, I'd like to source a.sh and b.sh. a.sh, however, might have already sourced b.sh. Thus it will cause the codes in b.sh executed twice. Is there any mechanism alike "include guard" in C++?
RNA
  • 146,987
  • 15
  • 52
  • 70
10
votes
2 answers

Include guard conventions in C

What is the conventional way to set up your include guards? I usually write them as (for example.h): #ifndef _EXAMPLE_H_ #define _EXAMPLE_H_ #include "example.h" #endif Does underscore convention matter? I've seen conflicting information when I…
cjubb39
  • 454
  • 1
  • 5
  • 15
1
2
3
12 13