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µÄº
Ïà¹ØÎĵµ£º
ʹÓÃNDK¿ª·¢C/C++ÏîÄ¿¹æÔò
<!-- /* Font Definitions */ @font-face {font-family:ËÎÌå; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;}@font-face {font-family:"\@ËÎÌå&qu ......
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 ......
//1.JavaÖÐ×Ö·û´®²»ÄܶàÐÐÊéд¡£¶àÐÐÊéдÓÃÒýºÅ¸ô¶Ï£¬¼ÓºÅÏàÁ¬¡£
//2.JavaµÄ±êʶ·û¿ÉÒÔÓÃÃÀÔª·ûºÅ¿ªÍ·¡£
//3.JavaÖÐûÓÐÎÞ·ûºÅ±äÁ¿»òÎÞ·ûºÅ³£Á¿µÄ¸ÅÄî¡£ËùÓеıäÁ¿¶¼ÊÇÓзûºÅµÄ¡£
//4.JavaÖбäÁ¿µÄ×Ö³¤Êǹ̶¨µÄ¡£²»´æÔÚcharºÍwcharÖ®·Ö¡£
//5.JavaÖбäÁ¿Î ......
1.ÓÐn¸öÕûÊý£¬Ê¹Ç°Ãæ¸÷Êý˳ÐòÏòºóÒÆm¸öλÖã¬×îºóm¸öÊý±ä³É×îÇ°Ãæm¸öÊý¡£
#include<stdio.h>
int f(int *);
int main()
{
int *p,a[10];
for(p=a;p<a+10;p++)
scanf("%d",p);
f(a);
for(p=a;p<a+10;p++)
printf("%d ",*p);
return 0;
}
int f(int *a)
{
int i,*p ......