C Traps and Pitfalls Ëæ±Ê
CÏÝÚåÓÚȱÏÝÕâ±¾Ê鵽ͼÊé¹Ý½èÁ˺ܾã¬Ò»Ö±¶¼Ã»ÓÐϸϸµÄ¿´£¬ÏÖÍêÕûµÄ¿´ÁËÖ®ºó°ÑÈÏΪÖØÒªµÄ£¬Ò»°ãÈË¿ÉÄܺöÊÓµÄÎÊÌâ¸ø×öÁ˱ʼǣ¬Ï£ÍûÓÐËù°ïÖú
2010.02.25
¶þάÊý×é:
int calendar[12][31];
int * p;
int i;
calendar[4]µÄº¬Ò壺
calendar[4]ÊÇcalendarÊý×éµÄµÚ5¸öÔªËØ£¬ÊÇcalendarÊý×éÖÐ12¸öÓÐ×Å31¸öÕûÐÍÔªËصÄÊý×éÖ®Ò»¡£
szieof(calendar[4])µÄ½á¹ûÊÇ31Óësizeof(int)µÄ³Ë»ý¡£
p=calendar[4];±íʾָÕëpÖ¸Ïòcalendar[4]ÖÐϱêΪ0µÄÔªËØ¡£
i=calendar[4][7];i=*(calendar[4]+7);i=*(*(calendar+4)+7);ΪͬÑùµÄ¹¦ÄÜ¡£
p=calendar;·Ç·¨£¬calendarÊÇÒ»¸ö¶þάÊý×飬¼´"Êý×éµÄÊý×é",±»×ª»»ÎªÒ»¸öÖ¸ÏòÊý×éµÄÖ¸Õ룻pΪָÏòÕûÐͱäÁ¿µÄÖ¸Õë¡£
int (*monthp)[31];monthp=calendar:ΪºÏ·¨µÄ¡£monthpÖ¸ÏòcalendarµÄµÚÒ»¸öÔªËØ
calendar[i][j]=0;Óë*(*(calendar+i)+j)=0;µÈ¼Û¡£
for(monthp=calendar;monthp< &calendar[12];monthp++)//¿ÉÒÔÓÃmonthp²½½øµÄ·½Ê½±ãÀûÊý×écalendar;
for(monthp=calendar;monthp< &calendar[12];monthp++)
int * dayp;
for(dayp=* monthp;dayp<&(*monthp)[31];dayp++)
*dayp=0;
×ܽ᣺
¿ÉÄÜÔÚCÓïÑÔÖжþάÊý×é²»ÊÇÁ¬Ðø·ÖÅäµÄ£¬µÚһάÖеÄÿһ¸öÔªËØΪµÚ¶þάÊý×éµÄÊ×µØÖ·¡£
·ÇÊý×éÖ¸ÕëʹÓãº
char * r;
r=malloc(strlen(s)+strlen(t)+1);
if(!r) //error control;
strcpy(r,s);
strcat(r,t);
//control;
fress(r);
mallocº¯Êý¿ÉÄÜÎÞ·¨ÌṩÇëÇóµÄÄڴ棬½«·µ»Ø¿ÕÖ¸Õë¡£
strlen·µ»Ø×Ö·û´®ÖÐËù°üº¬µÄ×Ö·ûÊýÄ¿£¬×÷Ϊ½áÊø±êÖ¾µÄ¿Õ×Ö·ûδ¼ÆËãÔÚÄÚ¡£strlen(s)µÄֵΪn£¬Ôò×Ö·û´®Êµ¼ÊÐèÒª£î+£±¸ö×Ö·ûµÄ¿Õ¼ä¡£
char hello[]="hello";
printf("%s\n",hello);Óëprintf("%s\n",&hello[0])µÈЧ¡£
char *p,*q;
p="xyz";//pµÄÖµ²»ÊÇ"xyz"£¬p¶øÊÇÖ¸Ïò×Ö·ûÊý×éµÄÆøÖÊÔªËصÄÖ¸Õ룻
q=p;//pºÍqÖ¸ÏòÄÚ´æÖÐͬһµØÖ·µÄÖ¸Õë¡£¸Ã¸³ÖµÓï¾ä²¢Ã»ÓÐͬʱ¸´ÖÆÄÚ´æÖеÄ×Ö·û
q[1]='Y';//q£¬pÖ¸ÏòµÄ×Ö·û´®¶¼¸Ä±ä¡£
Êý×éÖÐʵ¼Ê²»´æÔڵēÒç½ç”ÔªËصĵØַλÓÚÊý×éËùÕ¼ÄÚ´æÖ®ºó£¬Õâ¸öµØÖ·¿ÉÒÔÓÃÓÚ¸´ÖƺͱȽϣ¬ÒýÓøÃÔªËØÔò·Ç·¨¡£
static:
static int a£»±íʾaµÄ×÷ÓÃÓòÏÞÖÆÔÚÒ»¸öÔ´ÎļþÖУ¬¶ÔÓÚÆäËûÔ´Îļþ£¬aÊDz»¿É¼ûµÄ¡£staticÒ²ÊÊÓÃÓÚº¯Ê
Ïà¹ØÎĵµ£º
C/C++Í·ÎļþÒ»ÀÀ ÊÕ²Ø
C/C++Í·ÎļþÒ»ÀÀ
C¡¢´«Í³ C++
#include <assert.h>¡¡¡¡¡¡¡¡//É趨²åÈëµã
#include <ctype.h>¡¡¡¡¡¡¡¡ //×Ö·û´¦Àí
#include <errno.h>¡¡¡¡¡¡¡¡ //¶¨Òå´íÎóÂë
#include <float.h>¡¡¡¡¡¡¡¡ //¸¡µãÊý´¦Àí
#include <fstream.h>¡¡¡¡¡¡ //ÎļþÊäÈ룯Êä³ö
#i ......
SQLite3ÊÇSQLiteÒ»¸öȫеİ汾,ËüËäÈ»ÊÇÔÚSQLite 2.8.13µÄ´úÂë»ù´¡Ö®ÉÏ¿ª·¢µÄ,µ«ÊÇʹÓÃÁ˺Í֮ǰµÄ°æ±¾²»¼æÈݵÄÊý¾Ý¿â¸ñʽºÍAPI. SQLite3ÊÇΪÁËÂú×ãÒÔϵÄÐèÇó¶ø¿ª·¢µÄ:
Ö§³ÖUTF-16±àÂë.
Óû§×Ô¶¨ÒåµÄÎı¾ÅÅÐò·½·¨.
¿ÉÒÔ¶ÔBLOBs×ֶν¨Á¢Ë÷Òý.
Òò´ËΪÁËÖ§³ÖÕâЩÌØÐÔÎҸıäÁËÊý¾Ý¿âµÄ¸ñʽ,½¨Á¢ÁËÒ»¸öÓë֮ǰ°æ±¾²»¼æÈݵ ......
CRT È«³Æ£ºVisual C++ C RunTime Lib ¾ÍÊÇCÔËÐÐʱ¿â¡£
×¢£º ÒÔÏÂÄÚÈݲ¿·ÖÒý×ÔCSNDÖÐÏà¹ØÌÖÂÛµÄÌû×Ó£¬²¢½áºÏ×Ô¼ºµÄÀí½âÕûÀí¶ø³É¡£½ö¹©²Î¿¼¡£
1)ÔËÐÐʱ¿â¾ÍÊÇ C run-time library£¬ÊÇ C ¶ø·Ç C++ ÓïÑÔÊÀ½çµÄ¸ÅÄî:È¡Õâ¸öÃû×Ö¾ÍÊÇÒòΪÄãµÄ C ³ÌÐòÔËÐÐʱÐèÒªÕâЩ¿âÖеĺ¯Êý.
2)C ÓïÑÔÊÇËùνµÄ“СÄں˔ÓïÑÔ£¬¾ÍÆäÓ ......
CÖÐÔ¤±àÒëºê¶¨Òå
2010-01-07 11:49
ÔÚ½«Ò»¸öCÔ´³ÌÐòת»»Îª¿ÉÖ´ÐгÌÐòµÄ¹ý³ÌÖÐ, ±àÒëÔ¤´¦ÀíÊÇ×î³õµÄ²½Öè. ÕâÒ»²½ÖèÊÇÓÉÔ¤´¦ÀíÆ÷(preprocessor)À´Íê³ÉµÄ. ÔÚÔ´Á÷³ÌÐò±»±àÒëÆ÷´¦Àí֮ǰ, Ô¤´¦ÀíÆ÷Ê×ÏȶÔÔ´³ÌÐòÖеÄ"ºê(macro)"½øÐд¦Àí.
C ³õѧÕß¿ÉÄܶÔÔ¤´¦ÀíÆ÷ûʲô¸ÅÄî, ÕâÊÇÇéÓпÉÔµÄ: Ò»°ãµÄC±àÒëÆ÷¶¼½«Ô¤´¦Àí, »ã±à, ± ......
linux ÏÂc ³ÌÐò ¶Î´íÎó ·ÖÎö
(2008-12-31 16:50:57)
var $tag='it';
var $tag_code='2cec03ae0a5b0d224bb35c9b79dd54c7';
±êÇ©£ºit
·ÖÀࣺC/C++
fopen("/var/spool/cron/tmp","w+");
/////////////////////////////////////////
#include <sys/types.h>
......