Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) C++ Builder assert

 

The standard assert does not work nice in C++ Builder when working on a console application. Instead, one can use the code below, which does wait for a key press.

 

 

 

 

 

//---------------------------------------------------------------------------
#ifndef BilderbikkelConsoleAssertH
#define BilderbikkelConsoleAssertH
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/CppBuilderAssert.htm
#ifdef NDEBUG
  #define Assert(x) ((void)0)
#else
  #include <iostream>

  #define Assert(x)                      \
  if (! (x))                             \
  {                                      \
    std::cout                            \
      << "ERROR!! Assertion "            \
      <<  std::string (#x)               \
      <<  " failed\n on line "           \
      <<  (__LINE__)                     \
      <<  " in the function "            \
      <<  (__FUNC__)                     \
      <<  "\n in file "                  \
      <<  __FILE__                       \
      << std::endl;                      \
      std::string tempString;            \
      std::getline(std::cin,tempString); \
  }
#endif


#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