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

Why should avoid redundant declarations in C++?

I am learning multiple file compilation in C++ and found practice like this: #ifndef MY_LIB_H #define MY_LIB_H void func(int a, int b); #endif Some people say that this practice is adopted to avoid repeating declarations. But I try to declare a…
Bubble
  • 23
  • 4
0
votes
0 answers

#ifndef error : need to update includepath

My header file "broker.h" is #ifndef _BROKER_ #define _BROKER_ #include #include #include #include #include #include #include #include "strategy.h" #include "utils.h" using…
hyemin ju
  • 39
  • 6
0
votes
1 answer

about #ifndef and macro_function

i have changed complier from msvc to mingw, macro function : _countof was not inluded in mingw or #define _countof(array) (sizeof(array) / sizeof(array[0])) maybe it's only for msvc, so,i have to add the defination into header…
anti-gravity
  • 122
  • 6
0
votes
1 answer

#ifndef not letting my files see what's in the header (C++)

So I created a Binary tree class and I want to separate the class definition from its member function definition by putting the class def in the .h file and the function definitions in the .cpp file. Then I would include the .h file into the .cpp…
0
votes
2 answers

Redefinition error when using ifndef when alias is defined like "const int alias = variable" instead of #define

I defined const UInt8 HE = he; inside namespace Ports in ports.h. Then I included it in ports_logic.h and in ports_logic.h, I have the following code inside namespace Ports #ifndef HP const UInt8 HP = hp; #endif However during compilation, it gives…
the_naive
  • 2,936
  • 6
  • 39
  • 68
0
votes
0 answers

Why does the C(++) preprocessor allow be to define a macro but not check if it's not defined?

If I have a simple statement like this: #ifndef A(B) #define A(B) B #endif I get a compilation error... error: extra tokens at end of #ifndef directive [-Werror] #ifndef A(B) ^ But if I write (say): #ifndef A #define A(B) B #endif I…
adrianmcmenamin
  • 1,081
  • 1
  • 15
  • 44
0
votes
2 answers

ifndef isn't working; I have a header file included twice

My Ifndef isn't working. I have MapData.h included twice in both: Generate.cpp and Risky Strats.cpp MapData.h: #ifndef MAPDATA #define MAPDATA #include #include class bases { public: int x; int y; }; class field…
Random Guy
  • 61
  • 7
0
votes
1 answer

Conditional Compile of const static arrays

I am trying to create an error enum and associated text descriptors aligned in the same file. I have a system.cpp file that contains the following: #define SYSTEMCODE #include "myerrors.h" The file myerrors.h contains: typedef enum errors { …
0
votes
1 answer

Confusion with Preprocessor Directives

I have three files File "grandparent.h" #ifndef GRANDPARENT_H #define GRANDPARENT_H struct foo { int member; }; #endif /* GRANDPARENT_H */ File "parent.h" #include "grandparent.h" File "child.c" #include "grandparent.h" #include…
rooni
  • 1,036
  • 3
  • 17
  • 33
0
votes
1 answer

Redefined symbol in multiple c code with #ifndef directive

I have a stupid problem and I don't see where it comes from. I took care of using #ifndef directive to make sure all my #include are not redefined. Sadly for three of them that's happening. Here my multiple files arch : t_include.h #ifndef…
0
votes
1 answer

cpp - why didn't guardian protect me from multiple definitions?

I'm more into JAVA, but when HI-Perf is in the requirements list C/C++ must come on the table. And so it did. And, as expected, I'd stumbled upon something I cannot understand and cannot dig out in SO. So can anyone explain me why didn't guardian in…
netikras
  • 422
  • 4
  • 12
0
votes
0 answers

TUIO #ifndef WIN32 gets ignored

I am using the TUIO framework in Visual Studio 2013. When I build, the error 'pthread.h no such file or directory' appears. It seems TUIO runs on Linux and Windows and the #ifndef WIN32 checks for the operating system. While Visual seems to get it…
Jan V.
  • 180
  • 3
  • 12
0
votes
1 answer

Define statement expected a declaration C++

Okay, so I have narrowed the problem having to do with the #ifndef and/or the #define keywords. I have 2 other .h files and the only difference between the ones with no errors and the ones without is the syntax highlighting on the #ifndef EMPLOYEE_H…
Zelf
  • 21
  • 1
  • 5
0
votes
1 answer

C++ two header files include each other

There are three .h files A.h: #ifndef __A_H__ #define __A_H__ #include"Card.h" #include"B.h" struct A{ Card card; ..... }; void getCards(A *a, int num); #endif B.h #ifndef __B_H__ #define __B_H__ #include"Card.h" #include"A.h" struct…
soonoo
  • 867
  • 1
  • 10
  • 35
0
votes
1 answer

Having trouble with #ifndef in C++

I am creating a software for Raspberry pi using WiringPi. The problem is that WiringPi will fail if it does not detect a Raspberry Pi. So if I want to do some unit testing without using an actual Raspberry pi I have to check for a constant and do…
Razican
  • 697
  • 2
  • 10
  • 16