现在的位置: 首页 > 综合 > 正文

assert使用

2012年07月22日 ⁄ 综合 ⁄ 共 1505字 ⁄ 字号 评论关闭

多用assert,能很好找到程序出错位置。

测试
1、输入参数个数不等于2时

yuan@yuan:~/work/test> ./assert test
this is a test for assert,by yuanzhenhai
***ERROR***(argc != 3): "argc == 3" must be true, __funtion__:main(),  __file__:assert.c,  __line__:42

2、输入参数个数等于2,但两个参数字符串不相等时

yuan@yuan:~/work/test> ./assert test testtt
this is a test for assert,by yuanzhenhai
***ERROR***(the two string isn't equal): "!strcmp(str1,str2)" must be true, __funtion__:fun(),  __file__:assert.c,  __line__:32

3、输入参数个数等于2,两个参数字符串也相等时

yuan@yuan:~/work/test> ./assert test test
this is a test for assert,by yuanzhenhai
the two strings that you input is equal,successful!

抱歉!评论已关闭.