How to make conditional compilation in C++

1 Answer

0 votes
#define DEBUG_LEVEL 3

#include <iostream>
 
int main() {
 
#ifdef DEBUG_LEVEL
    std::cout << "1: yes\n";
#else
    std::cout << "1: no\n";
#endif
 
#ifndef DEBUG_LEVEL
    std::cout << "#ifndef DEBUG_LEVEL\n";
#elif DEBUG_LEVEL == 3
    std::cout << "#elif DEBUG_LEVEL == 3\n";
#else
    std::cout << "#else\n";
#endif
 
#if !defined(DEBUG_CPU) && (DEBUG_LEVEL < 5)
    std::cout << "yes\n";
#endif
}
 



/*
run:

1: yes
#elif DEBUG_LEVEL == 3
yes

*/

 



answered Dec 3, 2022 by avibootz

Related questions

1 answer 107 views
1 answer 126 views
1 answer 109 views
1 answer 132 views
1 answer 225 views
...