Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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++ÖУ¬GB2312תUnicode

    ǶÈëµ½¶à¸öϵͳ±à³Ìʱ³£³£³öÏÖ±àÂëÎÊÌ⣬ÌرðÊÇÖÐÎÄ£¬²¢ÇÒ¶ÔÓÚ¹ú±êGB2312À´Ëµ£¬²»ÏñUTF-8ÄÇÑù¿ÉÒÔÓÃËã·¨Ö±½ÓתΪunicode£¨´«ËµÊÇÕâô˵µÄ£¬ÎÒҲûÊÔ¹ý£©£¬ËùÒÔGBµ½UnicodeÖ»ÄÜÊÇÒ»¶ÔÒ»µÄת»»¡£
ÒÔÇ°Åöµ½¹ýGBתΪUnicodeµÄÄÑÌ⣬ÔÚÍøÉÏÕÒµ½ÁËÔ´Â룬ÎÒÖ»ÊÇÐÞ¸ÄÁËһϲéÕҵĴúÂ룬½«²éÕÒËã·¨¸ÄΪ¶þ·Ö²éÕÒ¡£
&n ......

Linux²Ù×÷ϵͳI2CÇý¶¯¼Ü¹¹

1£¬LinuxµÄI2CÇý¶¯¼Ü¹¹¸ÅÀÀ
      LinuxÖÐI2C×ÜÏßµÄÇý¶¯·ÖΪÁ½¸ö²¿·Ö£¬×ÜÏßÇý¶¯£¨BUS£©ºÍÉ豸Çý¶¯£¨DEVICE£©¡£ÆäÖÐ×ÜÏßÇý¶¯µÄÖ°Ôð£¬ÊÇΪϵͳÖÐÿ¸öI2C×ÜÏßÔö¼ÓÏàÓ¦µÄ¶Áд·½·¨£¨±ÈÈ粻ͬµÄÖ÷оƬ¼¯³ÉµÄI2C¿ØÖÆÆ÷£©¡£µ«ÊÇ×ÜÏßÇý¶¯±¾Éí²¢²»»á½øÐÐÈκεÄͨѶ£¬ËüÖ»ÊÇ´æÔÚÔÚÄÇÀµÈ´ýÉ豸Çý¶¯µ÷ÓÃÆäº ......

C/C++³ÌÐòԱӦƸ³£¼ûÃæÊÔÌâÉîÈëÆÊÎö(2)

C/C++³ÌÐòԱӦƸ³£¼ûÃæÊÔÌâÉîÈëÆÊÎö(2)
×÷ÕߣºËᦻª e-mail:21cnbao@21cn.com ³ö´¦£ºÈí¼þ±¨
 3.ÄÚ¹¦Ìâ
ÊÔÌâ1£º·Ö±ð¸ø³öBOOL£¬int£¬float£¬Ö¸Õë±äÁ¿ Óë“ÁãÖµ”±È½ÏµÄ if Óï¾ä£¨¼ÙÉè±äÁ¿ÃûΪvar£©
½â´ð£º
BOOL ÐͱäÁ¿£ºif(!var)
int ÐͱäÁ¿£º if(var==0)
float ÐͱäÁ¿£º
const float EPSINON = 0.00 ......

extern "C"


extern "C"°üº¬Ë«Öغ¬Ò壬ÆäÒ»£º±»ËüÐÞÊεÄÄ¿±êÊÇ“extern”µÄ£»Æä¶þ£º±»ËüÐÞÊεÄÄ¿±êÊÇ“C”µÄ¡£
1£©±»extern “C”ÏÞ¶¨µÄº¯Êý»ò±äÁ¿ÊÇexternÀàÐ͵ģ»
    externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©µÄ¹Ø¼ü×Ö£¬¸Ã¹Ø¼ü×Ö¸æËß±àÒëÆ÷£¬ÆäÉùÃ÷µÄº¯ÊýºÍ±äÁ¿¿É ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ