/*********************************************************
* Module : BAssert.h
*
* Purpose: Custom assert() and ASSERT() macros
*********************************************************/
#ifndef __BASSERT_H__
#define __BASSERT_H__
// Replace any existing assert and ASSERT with the
// macros in this file
#ifdef assert
#undef assert
#endif
#ifdef ASSERT
#undef ASSERT
#endif
// Define assert and ASSERT for debug and
// release builds
#if defined(_DEBUG)
// Define the debug macros
#define assert \
if(!)
{
cerr << "\nAssertion Failed: " << #a
<< "\nFailure occured on line "
<< _LINE_ << " of source file:"
<< "\n \"" << _FILE_ << "\"\n";
}
#define ASSERT(a,str) \
if(!)
{ \
cerr << "\nAssertion Failed: " << #a
<< " " << #str
<< "\nFailure occured on line "
<< _LINE_ << " of source file:"
<< "\n \"" << _FILE_ << "\"\n";
}
#else
// Define the release macros as nothing
//
#define assert
#define ASSERT(a,str)
#endif // #if defined(_DEBUG)
#endif // __BASSERT_H__
/*********************************************************
* Module : main.cpp
*
* Purpose : A driver program to demonstrate the
* assert() and ASSERT() macros defined in
* BAssert.h
*********************************************************/
#include <iostream.h>
#include "BAssert.h"
// Constant definitions
//
const int hearts = 0;
const int diamonds = 1;
const int clubs = 2;
const int spades = 3;
// Function prototypes
//
void Print(char *str);
void PrintSuit(int suit);
int NotYetImplemented();
/*******************************************************/
// main()
void main() {
assert(false); // Always fails
int x = 5;
assert(x==5); // this on''s okay
assert(x==10); //this on''s an error
ASSERT(x==10,"x should be 5!");
assert("This will fail" == 0); // Always fails
char *str1 = 0;
char *str2 = "\nA test string\n\n";
Print(str1);
Printf(str2);
PrintSuit(hearts);
PrintSuit(spades);
PrintSuit(10);
int y = NotYetImplemented();
}
/*******************************************************/
// Print()
void Print(char *str) {
ASSERT(str==0, "String should not be null");
if(str!=0)
cout<<str;
}
/*******************************************************/
// PrintSuit()
void PrintSuit(int suit) {
switch (suit)
case hearts:
cout<<"Hearts\n";
break;
case diamonds:
cout<<"Diamonds\n";
break;
case clubs:
cout<<"Clubs\n";
break;
case spades:
cout<<"Spades\n";
break;
default:
// Invalid suit detected
assert"Invalid suit detected"==0);
}
}
/*******************************************************/
// NotYetImplemented
int NotYetImplemented() {
assert("Function not yet implemented" == 0);
return 0;
}
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\useoldio.h(29): warning C4995:''_OLD_IOSTREAMS_ARE_DEPRECATE'': name was marked as #pragma deprecated
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\BAssert.h(41): error C2143: syntax error : missing'''' before''<<''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\BAssert.h(41): error C2501:''cer'' : missing storage-class or type specifiers
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\BAssert.h(41): error C2371:''cer'' : redefinition; different basic types
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\BAssert.h(41): error C2014: preprocessor command must start as first nonwhite space
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(29): error C2059: syntax error :''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(29): error C2143: syntax error : missing'''' before''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(29): error C2121:'''' : invalid character : possibly the result of a macro expansion
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(29): error C2065:'''' : undeclared identifier
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(29): error C2593:''operator <<'' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\ostream.h(87): could be''ostream &ostream::operator <<(streambuf *''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(29): error C2065:''_LINE'' : undeclared identifier
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(29): error C2065:''_FILE'' : undeclared identifier
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(32): error C2059: syntax error :''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(32): error C2143: syntax error : missing'''' before''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(32): error C2121:'''' : invalid character : possibly the result of a macro expansion
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(32): error C2593:''operator <<'' is ambiguous
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(33): error C2059: syntax error :''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(33): error C2143: syntax error : missing'''' before''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(33): error C2121:'''' : invalid character : possibly the result of a macro expansion
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(33): error C2593:''operator <<'' is ambiguous
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(35): error C2059: syntax error :''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(35): error C2143: syntax error : missing'''' before''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(35): error C2017: illegal escape sequence
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(36): error C2059: syntax error :''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(36): error C2143: syntax error : missing'''' before''''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(36): error C2121:'''' : invalid character : possibly the result of a macro expansion
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(36): error C2593:''operator <<'' is ambiguous
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\ostream.h(87): could be''ostream &ostream::operator <<(streambuf *''
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(42): error C2065:''Print'' : undeclared identifier
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(44): error C2065:''heart'' : undeclared identifier
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(54): error C2601:''Prin'' : local function definitions are illegal
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(55): error C2017: illegal escape sequence
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(79): error C2121:'''' : invalid character : possibly the result of a macro expansion
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(86): error C2601:''NotYetImplemente'' : local function definitions are illegal
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(87): error C2121:'''' : invalid character : possibly the result of a macro expansion
c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(90): fatal error C1075: end of file found before the left brace'''' at''c:\Documents and Settings\Brandon\My Documents\Visual Studio Projects\BRN\MyAssert\main.cpp(28'' was matched