N
Nephi Immortal
How do I write correct preprocessor to test condition if I want to
select two different codes. I define SECURE_ON. The print is
supposed to report "SECURE_CPP is active." Why do it report
"SECURE_CPP is inactive." when I tell to turn on SECURE_ON before
SECURE_CPP is turned on automatically?
If there is no solution, what is another option?
// Test.h
#ifndef TEST_H
#define TEST_H
#ifdef SECURE_ON
#define SECURE_CPP
#else
#undef SECURE_CPP
#endif
void print();
#endif // TEST_H
// Test.cpp
#include <iostream>
#include “Test.h”
void print()
{
#ifdef SECURE_CPP
std::cout << "SECURE_CPP is active." << std::endl;
#else
std::cout << "SECURE_CPP is inactive." << std::endl;
#endif // SECURE_CPP
}
// main.cpp
#define SECURE_ON
#include “Test.h”
int main()
{
print();
return 0;
}
select two different codes. I define SECURE_ON. The print is
supposed to report "SECURE_CPP is active." Why do it report
"SECURE_CPP is inactive." when I tell to turn on SECURE_ON before
SECURE_CPP is turned on automatically?
If there is no solution, what is another option?
// Test.h
#ifndef TEST_H
#define TEST_H
#ifdef SECURE_ON
#define SECURE_CPP
#else
#undef SECURE_CPP
#endif
void print();
#endif // TEST_H
// Test.cpp
#include <iostream>
#include “Test.h”
void print()
{
#ifdef SECURE_CPP
std::cout << "SECURE_CPP is active." << std::endl;
#else
std::cout << "SECURE_CPP is inactive." << std::endl;
#endif // SECURE_CPP
}
// main.cpp
#define SECURE_ON
#include “Test.h”
int main()
{
print();
return 0;
}