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

Why #ifndef MyPTK is executing when I changed target from MyPTK to MyPTK copy

I have two targets MyPTK and MyPTK copy, the MyPTK copy is a target which I have duplicated from MyPTK #ifndef MyPTK [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetLogoutTimer) name:UITouchPhaseBegan…
Nasir
  • 1,617
  • 2
  • 19
  • 34
0
votes
2 answers

How does the preprocessor know to translate HEADER_H to header.h?

Per this question, it seems there is some flexibility to how you can write that-- #ifndef _HEADER_H or: #ifndef __HEADER___H__ etc. It's not set in stone. But I don't understand why we're using underscores at all in the first place. Why can't I…
temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
0
votes
1 answer

#ifndef why to use an other name than the class name?

Classes declarations usually look like that: #ifndef MY_CLASS_20141116 #define MY_CLASS_20141116 ... class MyClass { ... } #endif My question is, why to not use the class name instead of redefining a new identifier: #ifndef…
Adrian Maire
  • 14,354
  • 9
  • 45
  • 85
0
votes
2 answers

Including another .h file only sees my structs, but not my functions

So to simplify, let's say I have a Page.h file with the following... #ifndef PAGE_H #define PAGE_H typedef struct Pgmap{ int test; }Page; void printPage(); #endif Where the Page.c defines printPage() and has... #include "Page.h" And, I have…
JoeManiaci
  • 435
  • 3
  • 15
0
votes
1 answer

User Defined Build Settings in Test Targets?

i have the following code in my unit tests: #ifndef SERVER_TEST NSLog(@"\n\n!!!--- YOU ARE RUNNING TESTS IN STUB MODE ---!!!\n\n!!!--- Server Responses will be stubbed ---!!!\n\n"); #else NSLog(@"\n\n!!!--- YOU ARE RUNNING TESTS IN LIVE MODE…
dornad
  • 1,274
  • 3
  • 17
  • 36
0
votes
2 answers

Error: #if[n]def expected an identifier

Originally my code was: #ifndef 2DO_H #define 2DO_H int ReadNumber(); void WriteAnswer(int Nsumber1, int Number2); #endif However I was getting an error #if[n]def expected an identifier. So I played around with it and realized that my…
jlcv
  • 1,688
  • 5
  • 21
  • 50
0
votes
1 answer

How #ifndef works in different files

So I was trying to include the libraries I have declared in my main.cpp to my header.h //In my main.cpp #include #include #include using namespace std; //In my header.h #ifndef HANOI_H #define HANOI_H #include…
Josh
  • 3,231
  • 8
  • 37
  • 58
-1
votes
2 answers

how in #ifdef identifier and #ifndef identifier declare identifiers

#ifdef MATHLIBRARY_EXPORTS #define MATHLIBRARY_API __declspec(dllexport) // How to determine the identifier above? // Where did `MATHLIBRARY_API` came from? #else #define MATHLIBRARY_API __declspec(dllimport) #endif Another example: #ifdef…
alireza m
  • 9
  • 3
-1
votes
1 answer

Need validation on a claim from Go Lang

I have been lately looking into GoLang -- coming from C++ background-- I am reading a paper which allegedly explains the reasoning behind making Golang, here is its link: https://talks.golang.org/2012/splash.article One of the claims being is,…
RaGa__M
  • 2,550
  • 1
  • 23
  • 44
-1
votes
4 answers

Can/should I type whatever I want after #ifndef?

Example: #ifndef HEADER_h #define HEADER_h #endif Instead of HEADER_h, can I do the following? #ifndef HEADER or #ifndef LIBRARY or #ifndef SOMETHING or #ifndef ANOTHERTHING etc.
user7089860
-1
votes
1 answer

C++ error C2535 even though I'm using pragma once

I'm getting a weird C2535 Error when I run my code. It consists of a three main classes (summarized below). There are some circular dependencies between them but they are preceded by #pragma once macros and should not be created more than one time.…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
-2
votes
1 answer

c++ forward declaration + ifndef also needs pointers

Array: #ifndef ARRAY_H #define ARRAY_H #include using namespace std; namespace Maifee{ class Value; class Array { public: Array(); vector _elements; }; } #endif // ARRAY_H Object : #ifndef OBJECT_H #define…
Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86
-2
votes
2 answers

How to execute a part of code inside a function only once using #ifndef?

//static int initialized; void print(struct student *arg) { #ifndef first_call #define first_call 1 //if (!initialized) { //initialized = 1; printf("sizeof(*arg1): %lu\n", sizeof(*arg)); //} #endif ... } I want to execute lines…
-2
votes
2 answers

C header file #ifndef #include error

I'm trying to figure out, how to use C headers with #ifndef and #include. Lets say I have these two header files: headerA.h: #ifndef HEADERA_H #define HEADERA_H #include "headerB.h" typedef int MyInt; TFoo foo; ... some other structures from…
Risinek
  • 390
  • 2
  • 16
-2
votes
1 answer

error while programming c++ using header

Here is my code, im trying to make my own string class but im stuck here... my teacher is not good :/ well i got so many errors but i want to know why this error appears "invalid preprocesing directive #ifndef_CADENA_H" #include…
1 2 3
4