C/C++ Assertions

// assert.cpp
// Author: A.G.Raja
// Website: agraja.wordpress.com
// Licence: GPL
#include <iostream>
using namespace std;
#define my_assert(x) \
if(!x) cout<<__FILE__<<”:assertion on line “; \
cout<<__LINE__<<” failed”<<endl;
int main()
{
int a,b;
a=0;
my_assert(a) // User defined assertion
assert(a); // Predefined assertion
}
// g++ assert.cpp
Download here.
assert.doc
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s