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
1
vote
1 answer

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 why these NR header files do not incorporate any…
1
vote
0 answers

Atmel Studio 6; Embedded C: Multiple Declaration Errors despite using Header Guards

I'm writing an embedded C application in Atmel Studio 6 for an AVR device. I'm not that good at "file hierarchy", but I've been doing my best. Also, thank you for taking the time to open this question. Here is a file structure of the offending…
Nick Williams
  • 253
  • 2
  • 12
1
vote
1 answer

Mechanics Fortran Preprocessor

I recently happened to come across the preprocessing option most Fortran compilers support these days (as explained e.g. in the Fortran Wiki) . Coming from a C background, I would like to better understand the mechanics and caveats related to the…
curly_pinguin
  • 148
  • 1
  • 6
1
vote
2 answers

Can I rely on the include guards in standard headers

I want to know if I can rely on the particular definitions of the include guards in standard headers. If I look on my system with Visual Studio I can see, for example, that stdint.h has the _STDINT defined. My question is if I can rely on this…
xaviersjs
  • 1,579
  • 1
  • 15
  • 25
1
vote
1 answer

Including other header inside include guard causes error

I have few different classes. Few pairs need to know about each other. To prevent the headache I've created one file to keep forward declarations of all troublesome classes along with proper include order. #ifndef GLPROJECT_H #define…
pkubik
  • 780
  • 6
  • 19
1
vote
1 answer

Why do some include guards have a defined value?

Usually when using include guards I write them like so: #ifndef FILENAME_H #define FILENAME_H ... #endif // FILENAME_H Now in some librarys I've seen something like: #ifndef FILENAME_H #define FILENAME_H 1 ... #endif // FILENAME_H After some…
Ragas
  • 130
  • 2
  • 11
1
vote
1 answer

Where to place #includes and Redundancies in Code (Header and Implementation Files)

I'm currently going through Accelerated C++ and I'm having a little bit of difficulty in understanding where I necessarily need to put #include's (whether in the header and/or source file) and mostly, whether I'm being redundant. I'd appreciate all…
Seyon
  • 481
  • 6
  • 13
1
vote
2 answers

C++: Understanding Header Files & Header Guards with Easy Addition Example

I can't get my head around headers and header guards. I've read other questions and their answers but I still can't make this work in Visual Studio 2013: main.cpp #include "stdafx.h" #include #include "add.h" int _tmain(int argc, _TCHAR*…
Chameleon
  • 13
  • 3
1
vote
2 answers

Why not just declare structs in headers? Wouldn't this make include-guards unnecessary?

I recently realized that while it is illegal to ever define something more than once in a given translation unit, it is perfectly legal to declare things (functions, variables, structs) as many times as you like. I was under the impression that the…
master_latch
  • 434
  • 5
  • 12
1
vote
2 answers

Forward Declaration?, Include guard?, or something else?

I have a parent class called Token I have two children classes, ErrorToken and EndToken. Each one of those classes needs to be able to create an object of the other, and return it through a function call. Each one has their own seperate header…
CamHart
  • 3,825
  • 7
  • 33
  • 69
1
vote
3 answers

Error when including the same file in 2 files and then including them in another file (in c)

i have a problem in C which i don't know how to solve. Suppuse i have 4 c files, a.c ; b.c ; c.c ; d.c, and for each one of them there is an .h file: a.h ; b.h ; c.h ; d.h, which of course they include. I want to do the following: a.h will…
or523
  • 141
  • 6
1
vote
2 answers

Do (Cross-compile) platform files require an include guard?

I'm writing a Cross-compiling Toolchain file for VxWorks. Since it's an unknown system to cmake a also have write platform files (those in ../Modules/Platform). Beside my toolchain file I have written these platform files so far: VxWorks.cmake…
ollo
  • 24,797
  • 14
  • 106
  • 155
1
vote
2 answers

C++ header redefinition (ws2ipdef.h)

I use in my project a lot of includes (but every header file use header guards like #ifndef _HEADER_H #define _HEADER_H ... #endif and now I'm getting this errors from ws2ipdef.h (automatically included of windows.h): c:\program files\microsoft…
leon22
  • 5,280
  • 19
  • 62
  • 100
1
vote
2 answers

how to include javascript files in Google Gears Worker (no DOM access)

how does one include other .js files in the .js of a Worker. Every "include" solution for Javascript that I've found does it by loading into a tag, which is not an option for Workers since they don't have access to the DOM. I see from your…
brad
  • 423
  • 2
  • 5
  • 11
1
vote
5 answers

Tricky include situation in C

I have a file named cpu.h that includes two other headers named register.h and addrmode.h. A cpu_t struct is defined in cpu.h that the two includes need for their functions. I try to include cpu.h in the two other include files, but nothing is…
Cory Walker
  • 4,809
  • 4
  • 28
  • 32