PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » 入门和基础知识 » assert的用法assert的用法
本页主题: assert的用法assert的用法 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

meiwang12363

该用户目前不在线
级别: 中级程序员
精华: 1
发帖: 1069
威望: 0 点
金钱: 0 PYMB
贡献值: 0 点
在线时间:8(小时)
注册时间:2007-04-26
最后登录:2007-09-04

assert的用法assert的用法


assert的用法
assert是验证assert后面的括号里的表达式是否为真的函数

1,定义:
ASSERT()是一个调试程序时经常使用的宏。
assert是验证assert后面的括号里的表达式是否为真的函数,若为假,程序运行的时候就会报错.
2,引用:
#include "stdafx.h"
3,主要方面:
检查指针是否为空;检查数值范围;
4,用例:
BOOL CSerialPort::InitPort(CWnd* pPortOwner, UINT  portnr)
{
assert(portnr > 0 && portnr < 5);//在1-4之间
assert(pPortOwner != NULL);//指针不能为空
// if the thread is alive: Kill
if (m_bThreadAlive)
{
  do
  {
  SetEvent(m_hShutdownEvent);
  } while (m_bThreadAlive);
  TRACE("Thread ended\n");
}
…………
}
顶端 Posted: 2007-08-20 09:19 | [楼 主]
PHP学会网 php培训网 PHP暑期培训 PHP寒假培训 PHP假期培训 » 入门和基础知识

时:11-23 04:51 Copyright © 2006 phpwhy.com 权
ICP05060669

曳息 -