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

code guards fail

Take this files: a.h #ifndef A_H #define A_H char EL[] = "el"; #endif a.cpp #include "a.h" b.h #ifndef B_H #define B_H #include "a.h" #endif b.cpp #include "b.h" main.cpp #include "b.h" #include "a.h" int main() { } This is only an example,…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141
1
vote
3 answers

Use of "#define FOO" with no value assigned - other than as include guard?

I'm trying to understand Steinberg's VST SDK. What's the use of this: #define PLUGIN_API without assiging any value in a header file and then PLUGIN_API occurring in many member functions' declarations/definitions for example like…
McNail
  • 100
  • 8
1
vote
0 answers

Difference between inline and header guards

I have a question about header guard and inline. I know that if you want to definition of function in header file you must use inline pre-descriptor.Because when you use inline function, this function will be copy by preprocessor for compiler…
KaruF
  • 47
  • 5
1
vote
1 answer

gcc/xCode -- #include that does not trigger an error (or warning) if the file does not exist?

Is this possible? Basically, what I want to do is something like this: #includeIfItExists "header.h" and if header.h does not exist, the compiler simply continues on its merry way.
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
1
vote
4 answers

How to use Laravel/sanctum in package development

I try to use the Laravel/Sanctum in a custom Laravel package. As in a default Laravel application, I added it to the composer file, added the migration and set it up in the routes file. The next error message appears: "Auth guard [sanctum] is not…
1
vote
3 answers

c header-guards are ignored?

Why does gcc ignore these header guards in this simple test program? The header file is: #ifndef MYHEADER_H #define MYHEADER_H #warning "header declared" int some_int=0; #endif And the two .c files are: main.c: #include "header.h" int main…
flobue
  • 69
  • 1
  • 6
1
vote
1 answer

Class does not name a type with header guard

Due to error, I needed to implement a header guard in my Header file and Cpp since I have never used it before I don't know what went wrong because on some classes it works and on one it just won't... Originally the problem was bigger, but I think I…
Maxdola
  • 1,562
  • 2
  • 10
  • 29
1
vote
2 answers

Eclipse CDT graying out wrong part of code under #ifndef

I have header base.h containing #ifndef GUARD_H #define GUARD_H #endif Eclipse CDT is graying out everything below #ifndef GUARD_H. This would be correct if GUARD_H were defined, but it is not. Actually, the only place where it is…
1
vote
0 answers

Is it still true that external include-guards lead to faster compiling times in large C++ projects?

Let me start by defining what is usually called "external include-guards". Suppose you have a header file called someheader.h and a code file called source.cpp. You can have the traditional include-guards inside someheader.h: //someheader.h #ifndef…
1
vote
4 answers

C++ - How can I avoid this header from appearing twice?

At: http://www.learncpp.com/cpp-tutorial/110-a-first-look-at-the-preprocessor/ Under Header guards, there are those code snippets: add.h: #include "mymath.h" int add(int x, int y); subtract.h: #include "mymath.h" int subtract(int x, int…
Simplicity
  • 47,404
  • 98
  • 256
  • 385
1
vote
0 answers

Translate headers to Cython

Is it feasible for Cython to have the ability to translate C headers Cython-directives? (See here, in Conditional Compilation). A similar suggestion was made here too. In my case, I would like these C-directives in my .h: /* myheader.h */ #define…
jimmy
  • 21
  • 5
1
vote
1 answer

C++ Do i need to define header guards for nested classes?

Please see the given example: #ifndef OUTER_H #define OUTER_H class Outer { class Inner { public: Innner(); }; }; #endif My question is: Do I need to create a header guard somewhere for my Inner class, or just one for the…
Anderson
  • 25
  • 6
1
vote
1 answer

Guard flag when dealing with memory allocation

I hava some trouble understanding about guard flag in the following code. // User-defined operator new. void *operator new( size_t stAllocateBlock ) { static int fInOpNew = 0; // Guard flag. if ( fLogMemory && !fInOpNew )…
Dinesh G
  • 129
  • 7
1
vote
3 answers

functions used in multiple classes

i sort of asked this before, but i used what i was told to try to get my program to work: Its probably because I am noob at C++, but I am having trouble using #ifndef due to the problem that my classes contain the same .h files. both s.h and t.h and…
helpme
  • 11
  • 1
1
vote
3 answers

#ifndef works only for "declaration" parts?

I have such as this IGlobal.h file: #ifndef _IGLOBALS_ #define _IGLOBALS_ #define _USE_MATH_DEFINES #define PLUG_NUM_CHANNELS 2 #define PLUG_NUM_PRESETS 1 #define PLUG_FPS 100 #define PLUG_PPQ 96 #define KNOB_NUM_FRAMES 128 #define…
markzzz
  • 47,390
  • 120
  • 299
  • 507