C/C++ÄÚ´æ¹ÜÀíÖ®ÄÚ´æй©¼ì²é
Ò»£® ¸ÅÊö
ÄÚ´æй©һֱÊÇÈí¼þ¿ª·¢ÈËÔ±×îÍ·´óµÄÎÊÌâÖ®Ò»£¬ÓÈÆäÏñC/C++ÕâÑù×ÔÓɶȷdz£´óµÄ±à³ÌÓïÑÔ£¬¼¸ºõÊÇÿһ¸öÓÃÆ俪·¢³öÀ´µÄÈí¼þ¶¼»á³öÏÖÄÚ´æй©µÄÇé¿ö¡£
Èç¹ûûÓÐÄÚ´æй©£¬ÊÀ½ç»òÐí»á±äµÄÃÀºÃ¡£È»¶ø£¬ÍêÈ«ÃÀºÃµÄÊÀ½çÊDz»´æÔڵģ¬ÎÒÃÇÄÜ×öµÄ¾ÍÊǾ¡Á¿ÈÃËü±äµÄ¸üÃÀºÃ¡£
¶þ£® ¹¤¾ß½éÉÜ
×ݹÛÄ¿Ç°ÊÐÃæÉÏÓв»ÉÙÄÚ´æй©¹¤¾ß£¬ÔÚÕâÀï¾Í²»¶à×ö½éÉÜ¡£±ÊÕß×î³£ÓõÄÊÇIBM¹«Ë¾³ö²úµÄIBM Rational Purify£¬ËµÆðPurifyÕⶫÎ÷£¬Îȶ¨ÐÔËäÈ»²»ÔõôÑù£¬µ«¹¦ÄܺÜÇ¿´ó¡£ËüÊÇIBM Rational PurifyPlus²úÆ·×éÖÐÈý½£¿ÍµÄÒ»Ô±¡£
PurifyÊÇÃæÏòC/C++, VB, JavaÓïÑÔ£¬²âÊÔÄÚ´æ´íÎó£¬Windows API·ÃÎÊ´íÎó£¬COM·½·¨µ÷ÓÃÇé¿öµÈ¡£
ͼ1. PurifyÖ÷½çÃæ
Purify¶ÔÓÚC/C++µÄ·ÖÎöÖ§³ÖÔ´´úÂ뼶£¬»òͨ¹ýÆäרÀû¼¼Êõ£º“Ä¿±ê´úÂë²åÈ루Object Code Insertion£©”¹¤×÷ÔÚÎÞÔ´´úÂ뼶¡£PurifyµÄ¹¦ÄÜÆäʵ·Ç³£Ö®Ç¿´ó£¬´Ë´ÎÎÒÃÇÖ»ÌÖÂÛÔõôͨ¹ýPurify½øÐÐC/C++ϵÄÄÚ´æй©·¢ÏÖ¡£ÔÚ½éÉÜËüµÄ¹¤×÷Á÷³ÌÇ°£¬ÎÒÃÇÀ´ÈÏʶһϼ¸¸öËõдÊõÓïµÄÒâ˼£º
l ABR£º Array Bounds Read£¬Êý×éÔ½½ç¶Á
l ABW£ºArray Bounds Write£¬Êý×éÔ½½çд
l FMR£ºFree Memory Read£¬¿Õ¼äÄÚ´æ¶ÁÈ¡
l IPR£º Invalid Pointer Read£¬ÎÞЧָÕë¶ÁÈ¡
l IPW£ºInvalid Pointer Write£¬ÎÞЧָÕëдÈë
l NPR£ºNull Pointer Read£¬¿ÕÖ¸Õë¶ÁÈ¡
l NPW£ºNull Pointer Write£¬¿ÕÖ¸ÕëдÈë
l UMR£ºUninitialized Memory Read£¬Î´³õʼ»¯ÄÚ´æÔĶÁ
l MLK£ºMemory leaks£¬ÄÚ´æй©
l MIU£ºMemory in use, ÄÚ´æʹÓÃÖÐ
l MPK£ºPotential memory leaks£¬Ç±ÔÚµÄÄÚ´æй©
µ±ÎÒÃÇÍê³ÉÁËÄ¿±ê´úÂ룬Éú³É¿ÉÖ´ÐгÌÐòÎļþºó£¬ÔÚPurifyÖмÓÔØËü£¬±ã¿É×Ô¶¯Íê³É¿ÉÖ´ÐгÌÐò½âÎö£¬ÔËÐУ¬·ÖÎöµÄÒ»Ó¦¹¤×÷¡£
ͼ2. Rational PurifyµÄ¹¤×÷Á÷³Ì
Èý£® й©³¡¾°¼°¼ì²â
ÏÖÔÚ£¬ÎÒÃǾÍÀ´×ö¼¸¸ö°¸Àý£¬¿´¿´Ð§¹ûÈçºÎ¡£¿ªÊ¼Ö®Ç°£¬ÏȽéÉÜһϱÊÕߵŤ×÷¼°²âÊÔ»·¾³£º
l Microsfot Windows XP Tablet PC Edition 2005 SP3
l 3GÄÚ´æ(ÔÙ¶àµÄÄÚ´æÒ²ÅÂй©J)
l Microsfot Visual Studio 2005
l IBM Rational Purify 7.0
ÔÚÕâÀïÏë¶îÍâµÄ˵Ã÷һϣ¬±ÊÕßÔø¾²âÊԶԱȹýVC2005ºÍVC6Éú³É³ÌÐò£¬·¢ÏÖVC2005Éú³É»ã±à´úÂëÖÊÁ¿±ÈVC6µÄº
Ïà¹ØÎĵµ£º
ÔÚCÓïÑÔÖУ¬escapeµÄ·ûºÅºÜºÃÓã¬
±ÈÈç
"ÖйúÒ»¶¨Ç¿"
Õâ¸ö×Ö´®¿ÉÒÔд³É£º
"\x4E2D\x56FD\x4E00\x5B9A\x5F3A"
ÓÃ×ÖÔª±àÂë±àд³ÌÐò£¬ÔÚÆäËû²»Í¬ÓïÑÔµÄwindowsÔË×÷ʱ£¬±È½Ï²»»áÓÐÎÊÌâ¡£
£¨ÎÒ¾¡Á¿²»ÏëÔÚ³ÌÐòÖÐдÈëÖÐÎÄ£©
µ«ÊÇvbÈç¹ûÈ«²¿ÒªÓÃ×ÖÔª±àÂëдµÄ»°£¬¾Í»áºÜÂé·³¶øÇÒÒ»¸öÒ»¸ö¶¼ÒªÊÖд³É£º
ChrW(&H4E2D) ......
²âÊÔ´úÂëÒ»£¨VC6.0¡¢C-code£©£º
#include <stdio.h>
void main()
{
int aa;
unsigned char j1,j2;
aa=j1=j2=0;
aa=49;
j1=aa;
printf("j1=%d \n",j1);
j2=aa;
printf("j2=%c \n",j2);
}
¡¾·ÖÎö¡¿£º
[1]ÕýÈçËùÏëÏóµÄÊä³ö½á¹û£º
j1 ......
Ò»¡¢¿ª·¢»·¾³
1¡¢ windowsXP
2¡¢ mysql 5.0.22
3¡¢ Dev-C++ 4.9.9.2
4¡¢ ÏÂÔØ(mysqlpp-2.3.2-gcc3.4.2-1due.DevPak)
5¡¢ MySQL.DevPak ÏÂÔصØÖ·£º http://downloads.sourceforge.net/dev-cpp/MySQL.DevPak
6¡¢ ÏÂÔØÒÔºóͨ¹ý‘¹¤¾ß[T]’ --> ´ò ......
(ת)C/C++ÖеÄÈÕÆÚºÍʱ¼ä time_tÓëstruct tmת»»
ͻ񻣼
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£ºUTC£¨ÊÀ½ç±ê ......
1.ÇóÏÂÃ溯ÊýµÄ·µ»ØÖµ£¨Î¢Èí£©
int func(x)
{
int countx = 0;
while(x)
{
countx
++;
x = x&(x-1);
}
return countx;
}
¼Ù¶¨x = 9999¡£ ´ð°¸£º8
˼·£º½«xת»¯Îª2½øÖÆ£¬¿´º¬ÓеÄ1µÄ¸öÊý¡£
2. ʲôÊÇ“ÒýÓÔ£¿ÉêÃ÷ºÍʹÓÓÒýÓÔҪעÒâÄÄЩÎÊÌ⣿
´ð£ºÒýÓþÍÊÇij¸öÄ¿±ê±äÁ¿µÄ&l ......