Questions tagged [ifndef]

Is one of the basic C/C++ pre processor macros to include/exclude specific parts of the source code to be compiled. "ifndef" branch is true if a specific pre-processor macro is not defined.

There are various C/C++ pre processor macros to control the compilation process. Some of them are used to include/exclude specific parts of the source code from compilation. These are conditional macros like #IF, #IFDEF, #IFNDEF.

Example:

#IFDEF __DEBUG__
    printf("This is a debug binary");
#ELSE
    printf("This is a release binary");
#ENDIF

If __DEBUG__ is defined "This is a debug binary" will be printed to console.

60 questions
1
vote
3 answers

Include Guards in C

I have 2 header files that have to include one other. config.h: #ifndef CONFIG #define CONFIG #include "debug.h" typedef struct Config_t { /* some stuff */ } Config; #endif debug.h #ifndef DEBUG #define DEBUG #include "config.h" void…
BeGreen
  • 765
  • 1
  • 13
  • 39
1
vote
2 answers

Multiple #ifndef statements - which one gets applied

Say I have five files: main.c, sample1.c, sample1.h, sample2.c and sample2.h, where in each of these files DEBUG_PRINTS is defined as follows: #ifndef DEBUG_PRINTS #define DEBUG_PRINTS 0 #endif and the code is compiled using gcc: gcc -Wall main.c…
Alexander
  • 921
  • 3
  • 12
  • 31
1
vote
1 answer

possible to use #ifndef on a function name?

I'm working with MicroPython and their header files use a ton of #ifndef function_name void function_name(const char *str, size_t len); #endif Using both an online C and C++ compiler, I tried the following code to test this in both C++ #include…
Bob
  • 4,576
  • 7
  • 39
  • 107
1
vote
1 answer

How to combine ifndef win32 with ifndef iOS

I have a C++ code section that I want to exclude it from building iOS. How should I do it? Follow up question: If I already have an #ifndef WIN32. I want to combine exclusion of WIN32 with iOS is it possible to do something like #ifndef WIN32 &…
TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159
1
vote
2 answers

Unexpected #ifndef, No Matching Function Call (Linked List C++)

Hi i am currently working on a linked list project but am receiving a few errors while doing so that I can't seem to solve. The first error i am getting is an undetermined #ifndef. What im confused about is that I didnt #include a source file in the…
Michael
  • 21
  • 5
1
vote
4 answers

C++ #ifndef TOKEN #define TOKEN

There has been a few cases where I've seen preprocessor code like the following: #ifndef TOKEN #define TOKEN #endif To me, it seems that in this situation (I'm aware of it's use when wrapped around items other than it's self (including include…
Razioark
  • 23
  • 4
1
vote
1 answer

WHY "already defined"?

Please suggest me a hint over here: class UIClass { public: UIClass::UIClass(); }; #ifndef __PLATFORM__ #define __PLATFORM__ UIClass Platform; #else extern UIClass Platform; #endif I'm including this two times and getting: LNK2005 -…
MixMix
  • 99
  • 8
1
vote
2 answers

Include Guards and #ifndef #define Preprocessing Statements

If I do the following: dConst.hpp const int POWER_LEVEL = 9001; genPower.hpp #include "dConst.hpp" #ifndef GENPOWER_HPP #define GENPOWER_HPP const int GENERATOR[1] = { POWER_LEVEL }; #endif I end up getting linker errors for any code that…
1
vote
1 answer

Multiple include error

I am new to C++ and am trying to include two .h files I made. The includes access each other so depending on the order I include them in one fails or the other. Because of this I know that the only possible problem has to be when I go to compile "$…
user3016327
  • 11
  • 1
  • 2
1
vote
2 answers

Using #ifndef breaks node-gyp module

I'm writing a node.js module using C++ and node-gyp but when I fix all the errors, like in this question, which included getting rid of redundant declarations by adding #ifndef BUILDING_NODE_EXTENSION and #endif to my files. Then I get the…
Loourr
  • 4,995
  • 10
  • 44
  • 68
1
vote
2 answers

ifndef, define & direct assignment of constants

I am just thinking of the difference between below methods, while defining constants: Method1: Create a header file to define all the constants, using include guard: #ifndef c1 #define c1 @"a123456789" #endif then assign the constant to the…
Kit Ng
  • 993
  • 4
  • 12
  • 24
0
votes
3 answers

Preprocessor #ifndef

Assume I have a.h which includes the following: Assume I also have b.h which also includes . If a.h has the #ifndef preprocessor definition statement in it and b.h doesn't. Will a.h include only what…
darksky
  • 20,411
  • 61
  • 165
  • 254
0
votes
1 answer

Use of Macro for static declaration

While reviewing C code that has been migrated from AIX to Cygwin 64-bit, I came across the following snippet. Writing only "static" within the "#ifndef" directive doesn't make sense to me. Since no documentation or help was available, I am asking…
aashoo
  • 404
  • 4
  • 13
0
votes
2 answers

ifndef with multiple AND conditions in makefile gnu

How do I ensure that make command has the parameter ENV passed in it? Eg: make destroy ENV=test if ENV is not passed I should throw error. Code: ENV ?=prod ifndef ENV $(error ENV is not defined, Please provide ENV paramter in your make…
Alfred Hitchkock
  • 357
  • 2
  • 14
0
votes
1 answer

Using ifndef in the makefile inside a variable defined by export

I want to insert ifndef in the makefile inside export And it seems that there is no possibility export LINKER_INCLUDE_FILES:=$(BASE_PATH)/build/one/bmw/r4_0_cantata/Deploy/src/platform/one/r4/cr4_cpu.o \ …