c¿âº¯ÊýÏê½â——assert
c¿âº¯ÊýÏê½â——assert
º¯ÊýÃû: assert
¹¦ ÄÜ: ²âÊÔÒ»¸öÌõ¼þ²¢¿ÉÄÜʹ³ÌÐòÖÕÖ¹
ÓÃ ·¨: void assert(int test);
³ÌÐòÀý:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
struct ITEM {
int key;
int value;
};
/* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
assert(itemptr != NULL);
/* add item to list */
}
int main(void)
{
additem(NULL);
return 0;
}
assert() º¯ÊýÓ÷¨
assertºêµÄÔÐͶ¨ÒåÔÚ<assert.h>ÖУ¬Æä×÷ÓÃÊÇÈç¹ûËüµÄÌõ¼þ·µ»Ø´íÎó£¬ÔòÖÕÖ¹³ÌÐòÖ´ÐУ¬ÔÐͶ¨Ò壺
#include <assert.h>
void assert( int expression );
assertµÄ×÷ÓÃÊÇÏÖ¼ÆËã±í´ïʽ expression £¬Èç¹ûÆäֵΪ¼Ù£¨¼´Îª0£©£¬ÄÇôËüÏÈÏòstderr´òÓ¡Ò»Ìõ³ö´íÐÅÏ¢£¬
È»ºóͨ¹ýµ÷Óà abort À´ÖÕÖ¹³ÌÐòÔËÐС£
Çë¿´ÏÂÃæµÄ³ÌÐòÇåµ¥badptr.c£º
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
int main( void )
{
FILE *fp;
fp = fopen( "test.txt", "w" );//ÒÔ¿ÉдµÄ·½Ê½´ò¿ªÒ»¸öÎļþ£¬Èç¹û²»´æÔھʹ´½¨Ò»¸öͬÃûÎļþ
assert( fp ); //ËùÒÔÕâÀï²»»á³ö´í
fclose( fp );
fp = fopen( "noexitfile.txt", "r" );//ÒÔÖ»¶ÁµÄ·½Ê½´ò¿ªÒ»¸öÎļþ£¬Èç¹û²»´æÔھʹò¿ªÎļþʧ°Ü
assert( fp ); //ËùÒÔÕâÀï³ö´í
fclose( fp ); &
Ïà¹ØÎĵµ£º
[C/C++ Digestion] –
×Ôµ×ÏòÉϵØÌ½¾¿Ð麯Êý
×÷Õߣº
Jason Lee @
http://blog.csdn.net/jasonblog
ÈÕÆÚ£º
2010-05-19
»·¾³£º
Visual C++ Express
2008
ÉùÃ÷£º±¾ÎÄ·¢±íÔÚ
csdn
²©¿Í£¬ÈçÓÐ×ªÔØ£¬Çë×¢Ã÷³ö´¦
[1]C++
¶ÔÏóÄ£ÐÍ»ù´¡
Ò»¸öÀàÖпÉÒÔ°üº¬¾²Ì¬Êý¾Ý³ÉÔ±¡¢¾²Ì¬³ÉÔ±º¯Êý¡¢·Ç¾²Ì¬³ÉÔ±º¯Êýº ......
c/c++Ö§³Ö¿É±ä²ÎÊýµÄº¯Êý£¬¼´º¯ÊýµÄ²ÎÊýÊDz»È·¶¨µÄ¡£
Ò»¡¢ÎªÊ²Ã´ÒªÊ¹Óÿɱä²ÎÊýµÄº¯Êý£¿
Ò»°ãÎÒÃDZà³ÌµÄʱºò£¬º¯ÊýÖÐÐÎʽ²ÎÊýµÄÊýĿͨ³£ÊÇÈ·¶¨µÄ£¬ÔÚµ÷ÓÃʱҪÒÀ´Î¸ø³öÓëÐÎʽ²ÎÊý¶ÔÓ¦µÄËùÓÐʵ¼Ê²ÎÊý¡£µ«ÔÚijЩÇé¿öÏÂÏ£Íûº¯ÊýµÄ²ÎÊý¸öÊý¿ÉÒÔ¸ù¾ÝÐèҪȷ¶¨£¬Òò´ËcÓïÑÔÒýÈë¿É±ä²ÎÊýº¯Êý¡£ÕâÒ²ÊÇc¹¦ÄÜÇ¿´óµÄÒ»¸ö·½Ã棬ÆäËüÄ³Ð©Ó ......
ÔÚ±à³ÌµÄ¹ý³ÌÖУ¬ÎļþµÄ²Ù×÷ÊÇÒ»¸ö¾³£Óõ½µÄÎÊÌ⣬ÔÚC++BuilderÖУ¬¿ÉÒÔʹÓöàÖÖ·½·¨¶ÔÎļþ²Ù×÷£¬ÏÂÃæÎҾͰ´ÒÔϼ¸¸ö²¿·Ö¶Ô´Ë×÷Ïêϸ½éÉÜ£¬¾ÍÊÇ£º
1¡¢»ùÓÚCµÄÎļþ²Ù×÷£»
2¡¢»ùÓÚC++µÄÎļþ²Ù×÷£»
3¡¢»ùÓÚWINAPIµÄÎļþ²Ù×÷£»
4¡¢»ùÓÚBCB¿âµÄÎļþ²Ù×÷£»
5¡¢ÌØÊâÎļþµÄ²Ù×÷¡£
¡¡
Ò¼¡¢»ùÓÚCµÄÎļþ²Ù×÷
¡¡¡¡ÔÚANSI CÖУ¬ ......
¾¡¹Ü Lua µÄ¹Ø¼ü´ÊµÄÉè¼Æ£¬ÔËÐзûµÄÉè¼Æ£¬Óï·¨µÄÉè¼ÆµÈ·½ÃæÓë C ºÜÏàËÆ£¬µ«ÎÒÃÇ»¹Òª×¢ÒâÆäÃ÷ÏÔ²»Í¬µÄµØ·½¡£
Ìõ¼þÅжÏʱµÄÕæ¼ÙÌõ¼þ
Lua ÖÐËùÓеÄÖµ¶¼¿ÉÒÔ×÷ΪÌõ¼þ¡£ÔÚ¿ØÖƽṹµÄÌõ¼þÖгýÁË false ºÍ nil Ϊ¼Ù£¬ÆäËûÖµ¶¼ÎªÕæ¡£ËùÒÔ Lua ÈÏΪ 0 ºÍ ¿Õ´® ¶¼ÊÇÕæ¡£
¶ø C ÖУ¬ÈÏΪֻҪÊÇÔÚÄÚ´æÖбíÏÖΪ 0 ÖµµÄ·ûºÅ¶¼Îª¼Ù¡£
×Ö ......
#include <stdio.h>
#include <string.h>
int
main(void)
{
char str[] =
"3BVPSq4xF.K?=u#,"
"G'K<MrDnRr7gH%#,"
"XKf<f%G`w^=?C<#,"
"HgU_AnNR?*PDQU#,"
......