[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppClxAssert

(C++ CLX) assert

See assert for the rationale of an assert statement.

Because in C++ Builder a program's window immediatly closes when using an ordinary assert, I provide an assert statement more practical in C++ Builder below.

  1. ifndef __BILDERBIKKEL_ASSERT_HPP
  2. define __BILDERBIKKEL_ASSERT_HPP
//#define this if you want to have a pure STL application
      1. ifdef BILDERBIKKEL_USE_STL_ONLY
          1. ifdef NDEBUG
              1. define Assert(x) ((void)0)
          2. else //Else of: #ifdef NDEBUG
              1. include <iostream>
              1. define Assert(x) \
if (! (x)) \ { \ std::cout \ << "ERROR!! Assertion " << #x \ << " failed\n"; \ << " on line " << __LINE__ << "\n"; \ << " in file " << __FILE__ << "\n"; \ std::cin.get(); \ std::exit(1); \ }
          1. endif //End of: #ifdef NDEBUG
      1. else //Else of: #ifdef BILDERBIKKEL_USE_STL_ONLY
          1. ifdef NDEBUG
              1. define Assert(x) ((void)0)
          2. else //Else of: #ifdef NDEBUG
              1. include <Dialogs.hpp> //For ShowMessage
              1. define Assert(x) \
if (! (x)) \ { \ ShowMessage( \ "ERROR!! Assertion " \ + String (#x) \ + " failed\n on line " \ + (__LINE__) \ + "\n in file " \ + (__FILE__) \ ); \ }
          1. endif //End of: #ifdef NDEBUG
      1. endif //Else of: #ifdef BILDERBIKKEL_USE_STL_ONLY
  1. endif //End of: #ifndef __BILDERBIKKEL_ASSERT_HPP


'Assert' links

Code links



last edited (March 21, 2007) by bilderbikkel, Number of views: 427, Current Rev: 1

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.