首先我们来看一下大家学习中经常熟悉用到的strlen函数。strlen1:指针差值返回intmy_strlen(constchar*str)
{
char*pst=(char*)str;
assert(str);
while(*str)
{
str++;
}
returnstr-pst;
}strlen2:递归实现intmy_strlenT(constchar*str)
{
assert(str);
if(*str)
return1+my_..
分类:
其他好文 时间:
2015-09-19 19:48:53
阅读次数:
326
在某些情况下,我们断定目标方法会抛出异常,这时该如何处理呢。 ? ? 使用junit测试抛出的异常,我总结了3种方式,详见代码: import?static?org.junit.Assert.fail;
import?org.junit.Rule;
import?...
分类:
其他好文 时间:
2015-09-17 19:59:39
阅读次数:
165
char*my_strcpy(char*arr,constchar*str)
{
char*pstr=arr;
assert(arr!=NULL&&str!=NULL);
while(*arr++=*str++)
{
;
}
returnpstr;
}
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
intmy_strcmp(constchar*str1,constcha..
分类:
其他好文 时间:
2015-09-17 15:31:54
阅读次数:
106
Java 关键字列表 (依字母排序 共51组):abstract, assert,boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum,extends, fin...
分类:
编程语言 时间:
2015-09-17 11:47:41
阅读次数:
212
assert 是C里面的宏。用于断言。assert的作用是现计算表达式 expression ,如果其值为假(即为0),那么它先向stderr打印一条出错信息,然后通过调用 abort 来终止程序运行。NSAssert 只能在Objective-c里面使用。是assert的一个扩充。能捕获asser...
分类:
移动开发 时间:
2015-09-11 12:32:16
阅读次数:
205
断言是很早之前就有的东西了,只需要引入cassert头文件即可使用。往往assert被用于检查不可能发生的行为,来确保开发者在调试阶段尽早发现“不可能”事件真的发生了,如果真的发生了,那么就表示代码的逻辑存在问题。最好的一点就是,断言只在Debug中生效,因此对于Release版本是没有效率上的.....
分类:
编程语言 时间:
2015-09-11 10:28:51
阅读次数:
155
#include<iostream>#include<assert.h>typedefintDatatype;usingnamespacestd;structLinkNode{ Datatype_data; LinkNode*_next; LinkNode(constDatatype&x) :_data(x) ,_next(NULL) {}};classSlist{public: Slist() :_head(NULL) ,_tail(NULL) {} ~Slist()..
分类:
其他好文 时间:
2015-09-11 06:57:30
阅读次数:
206
#include<stdio.h>#include<assert.h>#include<stdlib.h>//模拟memcpyvoidmy_momcpy(char*dest,constchar*str,intcount){assert(dest!=NULL);assert(str!=NULL);char*ret=dest;inti=0;for(i=0;i<count;i++){*dest++=*str++;}}intmain(){chara[100]="abcde..
分类:
其他好文 时间:
2015-09-10 17:46:33
阅读次数:
198
我一直以为assert仅仅是个报错函数,事实上,它居然是个宏,并且作用并非“报错”。 在经过对其进行一定了解之后,对其作用及用法有了一定的了解,assert()的用法像是一种“契约式编程”,在我的理解中,其表达的意思就是,程序在我的假设条件下,能够正常良好的运作,其实就相当于一个if语句:1 ...
分类:
其他好文 时间:
2015-09-10 17:22:32
阅读次数:
133
3 import static org.junit.Assert.assertTrue; 4 5 import java.util.Date; 6 import java.util.HashMap; 7 import java.util.List; 8 import java.uti...
分类:
编程语言 时间:
2015-09-09 11:27:19
阅读次数:
275