void assert( int expression );
// crt_assert.c
// compile with: /c
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyze_string( char *string ); // Prototype
int main( void )
{
char test1[] = "abc", *test2 = NULL, test3[] = "";
printf ( "Analyzing string '%s'\n", test1 ); fflush( stdout );
analyze_string( test1 );
printf ( "Analyzing string '%s'\n", test2 ); fflush( stdout );
analyze_string( test2 );
printf ( "Analyzing string '%s'\n", test3 ); fflush( stdout );
analyze_string( test3 );
}
// Tests a string to see if it is NULL,
// empty, or longer than 0 characters.
void analyze_string( char * string )
{
assert( string != NULL ); // Cannot be NULL
assert( *string != '\0' ); // Cannot be empty
assert( strlen( string ) > 2 ); // Length must exceed 2
}
Analyzing string 'abc' Analyzing string '(null)' Assertion failed: string != NULL, file assert.cpp, line 25 abnormal program termination
int resetBufferSize(int nNewSize)
{
//功能:改变缓冲区大小,
//参数:nNewSize 缓冲区新长度
//返回值:缓冲区当前长度
//说明:保持原信息内容不变 nNewSize<=0表示清除缓冲区
assert(nNewSize >= 0);
assert(nNewSize <= MAX_BUFFER_SIZE);
...
}
Analyzing string 'abc' Analyzing string '(null)' Analyzing string ''
void* memcpy(void *dst, const void *src, size_t count)
{
//安全检查
assert( (dst != NULL) && (src != NULL) );
unsigned char *pdst = (unsigned char *)dst;
const unsigned char *psrc = (const unsigned char *)src;
//防止内存重复
assert(!(psrc<=pdst && pdst<psrc+count));
assert(!(pdst<=psrc && psrc<pdst+count));
while(count--)
{
*pdst = *psrc;
pdst++;
psrc++;
}
return dst;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有