¶¨Ò壺
#include
void abort(void);
×÷ÓãºÇ¿ÐÐÖÕÖ¹³ÌÐò (Òì³£ÖÕÖ¹)¡£Èç¹ûµ±Ç°shell²»ÏÞÖÆulimit£¬½«»ácore dump¡£
2¡¢assertºê
ÔÐÍ£º
#include
void assert(int expression);
×÷Ó㺼ÆËã expressionµÄÖµ£¬ÈôÆä·µ»Ø0£¨¼Ù£©£¬ÔòÏò stderr´òÓ¡³ö´íÐÅÏ¢£¬²¢µ÷Óà abortÖÕÖ¹³ÌÐò¡£
ʹÓÃ×¢ÒâÊÂÏassertÒ»°ãÔÚ¿ª·¢½×¶ÎÓÃÓÚµ÷ÊÔ¡£Îª·ÀÖ¹¶¨ÒåNEBUGºóassert±»½ûÓã¬×îºÃ²»ÒªÖ±½ÓÏòassert½øÐÐÊäÈ룬¶øÊÇÈçÏÂËùʾ£º
p = malloc (sizeof (char) *100);
assert(p);
3¡¢exit
ÔÐÍ£º
#include
void exit(int status);
×÷Ó㺷µ»ØÒ»¸ö״ֵ̬¸ø²Ù×÷ϵͳ£¬statusÔÚstdlib.hÖж¨ÒåÁËEXIT_SUCCESSºÍEXIT_FAILURE¡£
4¡¢atexit
ÔÐÍ£º
#include
int atexit(void (*function)(void));
×÷Óãº×¢²áÒ»¸öº¯Êý£¬Õâ¸öº¯Êý¿ÉÒÔ¶¨ÒåһЩ²Ù×÷£¬ÓÃÀ´ÔÚ³ÌÐòÕý³£Í˳öʱִÐÐÖ®¡£atexit×¢²á³É¹¦Ôò·µ»Ø0,·ñÔò·µ»Ø1;¿ÉÒÔÓá°,¡±¸ô¿ª×¢²á¶à¸öº¯Êý£¬Ö´ÐÐ˳ÐòΪ×î×ó±ßµÄ×îºóÖ´ÐС£
5¡¢errno±äÁ¿£º
¶¨Ò壺
#include
int errno;
×÷ÓãºÈ«¾Ö±äÁ¿£¬Linuxϵͳµ÷ÓÃÓë´ó²¿·Ö¿âº¯ÊýÉèÖøÃÖµ£¬errno.h¶¨ÒåÁËÆäÖµ¶ÔÓ¦µÄ´íÎó¡£ÀýÈçENOENT´ú±íNo such file or directoryµÈ¡£º¯Êýperror¿ÉÒÔ´òÓ¡ÏàÓ¦µÄ³ö´íÐÅÏ¢¡£
×¢ÒâÊÂÏºÜ¶àº¯Êý·µ»Ø²¢ÉèÖÃerrnoºó²¢²»»á°ÑÖ®Çå0,Èç¹ûµ÷ÓÃÒ»¸ö¿ÉÄÜÔÚ³ö´íʱÉèÖÃerrnoµÄ¿âº¯ÊýµÄʱºò£¬×îºÃÏÈÊÖ¶¯°ÑerrnoÇåÁã¡£
6¡¢strerror
ÔÐÍ£º
#include
char *strerror(int errnum);
×÷Ó㺰Ñerrnoת»»³É±ê×¼µÄ³ö´íÐÅÏ¢¡£ÀýÈ磺
ps = strerror(ENOENT);
ÔòÖ¸ÕëpsÖ¸ÏòµÄ×Ö·û´®Îª"No such file or directory "µÈ¡£
7¡¢perror
ÔÐÍ£º
#include
#include
void perror(const char *s);
×÷Ó㺴òÓ¡sËùÖ¸µÄ×Ö·û´®ºÍ±ê×¼³ö´íÐÅÏ¢£¬Ï൱ÓÚ
printf("%s: %s\n", *s, strerror(errno));
Jusyliu ÓÚ 2012-04-09 20:36:58·¢±í:
¹ØÓÚassertÒ»Ö±²»ÊǺܻáÓ㬸оõËûÓÐЩÈú¯Êý¿ÉÔĶÁÐÔ½µµÍÁË£¡