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
0
votes
5 answers

Valid uses for C++ include guards besides, well, include-guarding?

This question is one of several that discuss naming conventions for C++ include guards. The person asking that question thinks that this naming convention: #ifndef FOO_H #define FOO_H // ... #endif is a bit non-intuitive when taken by itself…
John
  • 15,990
  • 10
  • 70
  • 110
0
votes
3 answers

C Issue with include guards

I have a header file which has an include guard setup. I have multiple C files in my project that require this header file for compilation. When I go to compile however I get an error saying that the function has already been included from another…
PleaseNoBugs
  • 169
  • 1
  • 10
0
votes
4 answers

Should we guard #include with #ifndef if the targeted file already has header guard?

Let's say we have two class, Foo and Bar. in Foo.h #ifndef MYPROJ_FOO #define MYPROJ_FOO .... # endif in Bar.cpp, do we still need to guard the include such as #ifndef MYPROJ_FOO #include #endif or simple #include is sufficient? It…
Syenun
  • 55
  • 8
0
votes
1 answer

Make sure every header uses unique include guards in big project

In a not-so-tiny project (>100 .h), I want to make sure that every .h use different include-guards (#ifndef XXX). Whenever I violate it, I want to be informed as soon as possible. Situation Here is the convention I am using…
javaLover
  • 6,347
  • 2
  • 22
  • 67
0
votes
2 answers

C++ Include guards

I know this been asked a number of times but no answers seem to solve this. I have two files. Main.cpp #include #include #include #include #include "Scene.h" #include "Camera.h" #include…
Kurieita
  • 83
  • 12
0
votes
4 answers

C++/SDL problem of double inclusion

I'm getting this error from compilator: 1>Linking... 1>main.obj : error LNK2005: "int g_win_flags" (?g_win_flags@@3HA) already defined in init.obj 1>main.obj : error LNK2005: "struct SDL_Surface * g_screen" (?g_screen@@3PAUSDL_Surface@@A) already…
peto1234
  • 369
  • 5
  • 11
0
votes
0 answers

Include guards in C++

I use include guards quite a lot, but I've recently found a strange use of them which I cannot understand. #ifndef B1SteppingAction_h #define B1SteppingAction_h 1 // rest of my code #endif What's that "1" in the define guard? I haven't found this…
0
votes
0 answers

C++ error: expected class-name before ‘{’ token { inheritance

I have a superclass Letter.h #ifndef LETTER_H //I have tried ifdef but it give me list of undefined reference and variables out of scope #define LETTER_H #include "A.h" using namespace std; class Letter{ //variables are declared in…
0
votes
0 answers

pragma once or ifndef define endif

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 foo() { return 0; } #endif // main.cpp #define…
user6911618
0
votes
2 answers

Syntax Error: missing ; before *

When I try to run these headers: Direct3D.h #pragma once //Library Linker #pragma comment(lib, "d3d11.lib") #pragma comment(lib, "dxgi.lib") //Includes #include //My Includes #include "SimpleShaderRessource.h" class…
Rafiwui
  • 544
  • 6
  • 19
0
votes
4 answers

Need clarification on #ifndef #define

The code I am working has multiple headers and source files for different classes face.cc, face.hh, cell.cc, cell.hh edge.cc edge.hh and the headers contain includes like this, #ifndef cellINCLUDED #define cellINCLUDED #ifndef…
jkhadka
  • 2,443
  • 8
  • 34
  • 56
0
votes
1 answer

Remove random part of an header guard from many header files

I've a program (an IDL compiler) that creates a bunch of header files. These header files have a header guard with a random part at the end, like this: #ifndef AUTOMATEDGENERATEDCODEIMPL_H_U1CBCG #define AUTOMATEDGENERATEDCODEIMPL_H_U1CBCG // My…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
0
votes
1 answer

makefile with 2 source directories make include guard fail

I have a project with sources in 2 locations. When the project links, it complains that a function is double-defined (it's not): cc -c -c -w -fPIC -g3 -Og -D__EMULATE_SOS__ -I../../libSOS/trunk/include -I. -I../../include -I../lib/ABCUtilSO/src…
clogwog
  • 343
  • 2
  • 13
0
votes
2 answers

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 guard. Example: #ifndef…
Dimitar
  • 4,402
  • 4
  • 31
  • 47
0
votes
2 answers

C++ Error LNK2005 When Adding a New HeaderFile

I am working on a project for school. I am aware of my circular dependency(And have read most of the resolutions here for that previously) but it works currently the way I need it to. Sadly I'm pretty sure it is also the cause of my woes. I would…