Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) #undef

 

#undef is a preprocessor directive to undo a #define.

 

#include <iostream>

#define MY_DEFINE

int main()
{
  #ifdef MY_DEFINE
  std::cout << "MY_DEFINE is #defined\n";
  #else
  std::cout << "MY_DEFINE is not #defined\n";
  #endif

  #undef MY_DEFINE

  #ifdef MY_DEFINE
  std::cout << "MY_DEFINE is #defined\n";
  #else
  std::cout << "MY_DEFINE is not #defined\n";
  #endif
}

 

Screen output:

 

MY_DEFINE is #defined
MY_DEFINE is not #define

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: CppUndef.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp

 

 

 

 

 

main.cpp

 

#include <iostream>

#define MY_DEFINE

int main()
{
  #ifdef MY_DEFINE
  std::cout << "MY_DEFINE is #defined\n";
  #else
  std::cout << "MY_DEFINE is not #defined\n";
  #endif

  #undef MY_DEFINE

  #ifdef MY_DEFINE
  std::cout << "MY_DEFINE is #defined\n";
  #else
  std::cout << "MY_DEFINE is not #defined\n";
  #endif
}

 

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml