《C++ Primer中文版(第三版)》
ISBN: 9787508309897
看到
" "
#include <assert.h>
下面是一个简单的使用示例:
assert( filename != 0 );
/*#include <iostream>
using std::cout;
int read()
{
//cout << "read()\n";
return -1;
}
void sort()
{
cout << "sort()\n";
}
void compact()
{
cout << "compact()\n";
}
void write()
{
cout << "write()\n";
}
int main()
{
int count = read();
if (count > 1)
{
sort();
compact();
}
if (count == 0)
{
cout << "no sales for this month\n";
}
else // count = 1
{
write();
}
return 0;
}*/
/* assert example */ // www.cplusplus.com
#include <stdio.h>
#define NDEBUG
#include <assert.h>
void print_number(int* myInt) {
assert (myInt!=NULL);
printf ("%d\n",*myInt);
}
int main ()
{
int a=10;
int * b = NULL;
int * c = NULL;
b=&a;
print_number (b);
print_number (c);
return 0;
}