¹ØÓÚCµÄ˼¿¼
¹ØÓÚCµÄ˼¿¼
Cong Wang
May, 2006
Network Engineering Department
Institute of Post and Telecommunications, Xi'an, P.R.China
ÒýÑÔ
CÓïÑÔ½áºÏÁË»ã±àµÄËùÓÐÍþÁ¦£¬ËüµÄ³éÏó³Ì¶ÈÅöÇɼÈÂú×ãÁ˳ÌÐòÔ±µÄÒªÇó, ÓÖÈÝÒ×ʵÏÖ¡£ÒòÆä¶ÀÌصÄÁé»îÐÔºÍÇ¿´óµÄ¿ÉÒÆÖ²ÐÔ£¬ÏµÍ³³ÌÐòÔ±ºÍºÚ¿ÍÃǸüÊǶÔËüÖÓ°®Óмӡ£ÎÞÒÉ£¬CÓïÑÔ»ñµÃÁË¿ÕÇ°µÄ³É¹¦£¬ÔÚijÖ̶ֳÈÉÏÉõÖÁ±ÈUNIX»¹Òª³É¹¦¡£È»¶ø£¬“CÓïÑÔ¾ÍÏñÒ»°Ñ¿Ìµ¶£¬¼òµ¥£¬·æÀû£¬²¢ÇÒÔÚ¼¼Ê¦ÊÖÖзdz£ÓÐÓ᣺ÍÈκηæÀûµÄ¹¤¾ßÒ»Ñù£¬C»áÉ˵½ÄÇЩ²»ÄܼÝÔ¦ËüµÄÈË¡£” [8]CÓïÑÔÁé»îÐԵı³ºó£¬ÓÐןܶàµÄҪעÒâºÍ±ÜÃâµÄµØ·½£¬Ò»²»Ð¡ÐÄÄã¾Í»áÏÝÈëbugµÄÄà̶¡£ËùÒÔÒ²ÎÞ¹ÖºõÖ»ÓÐCÓïÑÔ²ÅÓÐÏñ¡¶The C Puzzle Book¡·£¬¡¶Obfuscated C and Other Mysteries¡·£¬¡¶C Traps and Pitfalls¡·Ö®ÀàµÄÊé¡£ÏÂÃæµÄÎÄÕ²»ÊǶÔÄÇЩÊéÖÐÌáµ½µÄÎÊÌâµÄÖظ´£¬¶øÊǶÔÆäËüһЩϸСµÄµØ·½ºÍ²¿·ÖC¿âº¯Êý½øÐÐÌÖÂÛ¡£ ´ó²¿·Ö¶¼»á¼¯Öе½±ê×¼CÉÏ£¬²Î¿¼µÄ±ê×¼ÊÇISO C99£¬Ò»Ð¡²¿·Ö¿ÉÄÜ»áÉæ¼°µ½¾ßÌåƽ̨¡£
Ò». sizeofÓëreturn
sizeof²»ÊǺ¯Êý£¬¶øÊÇÒ»Ôª²Ù×÷·û£¬Ã»±ØÒª¸øËüºóÃæµÄ±í´ïʽ¼ÓÀ¨ºÅ¡£µ«Èç¹û¼ÆËãµÄÊÇÒ»ÖÖÀàÐ͵ĴóС£¬sizeof¾ÍÐèÒª¼ÓÒ»¸öÔ²À¨ºÅ£¬µ«Õâ²»ÊÇ˵ËüÊÇÒ»¸öº¯Êý¡£ return²»ÊǺ¯Êý£¬¶øÖ»Êǹؼü×Ö£¬Ò²²»ÐèÒªÔ²À¨ºÅ¡£»¹ÒªÌرð×¢ÒâµÄÊÇsizeof²Ù×÷·û“·µ»Ø”µÄÊÇÎÞ·ûºÅÕûÊý£¨size_t£©£¬Èç¹û°ÑËüµÄ“·µ»ØÖµ”ºÍÒ»¸öintÀàÐͱȽϣ¬ÏÈÒª°ÑËüת»¯³ÉÓзûºÅÕûÊý¡£ÁíÍ⣬Unixϵͳµ÷ÓÃread/writeµÄ·µ»ØÀàÐÍÊÇssize_t£¬¶ø²»ÊÇsize_t¡£ ssize_t´ú±ísigned size¡£
¶þ. 0.0,¡¡0,¡¡'\0' vs NULL£¬NUL
NULL±íʾµÄÊÇ¿ÕÖ¸Õ룬ËüºÍÈκηǿÕÖ¸ÕëÖµ¶¼²»ÏàµÈ¡£¶øNUL¾ÍÊÇ'\0'£¬±íʾµÄÊÇֵΪ0µÄ¿Õ×Ö·û¡£ËäÈ»0.0, 0, '\0', NULL¶¼ÊÇÍêÈ«ÓÉ0±ÈÌØ×é³É,µ«ÊÇËüÃǵij¤¶È²»Í¬¡£0.0ÊÇË«¾«¶È£¬Í¨³£ÊÇ8¸ö×Ö½Ú£»'\0'ÊÇ×Ö·û³£Á¿£¬Í¨³£Ö»ÓÐ1¸ö×Ö½Ú£»NULL±íʾ¿ÕÖ¸Õ룬ËüµÄ³¤¶ÈÓÉϵͳ¾ö¶¨£¬Ò²¾ÍÊÇϵͳÖд¢´æÒ»¸öÄÚ´æµØÖ·ËùÐèµÄ×Ö½ÚÊý£»0±íʾÕûÊý,Ò»°ãÊÇ4¸ö×Ö½Ú¡£ËüÃǵÄÀàÐͲ»Í¬£¬ÔÚÓÃËüÃǸø±äÁ¿¸³ÖµÊ±Ó¦¸ÃСÐÄ£¬ÓбØҪʱ½øÐÐÇ¿ÖÆת»»¡£×¢Ò⣺CÓïÑÔ²»±£Ö¤char×ÜÊÇ8¸ö±ÈÌØ£¬Ò²ÓÐ7¸ö»ò9¸ö±ÈÌصÄ×Ö·û£¡ËäȻûÓй涨shortÊÇ16¸ö±ÈÌØ£¬intÊÇ32¸ö±ÈÌØ£¬µ«ÊÇÔÚÄ¿Ç°µÄËùÓй¹¼ÜÉ϶¼ÊÇÈç´Ë¡£ long²¢²»×ܺÍintÒ»Ö£¬ËüÓë»úÆ÷×Ö³¤Ò»Ö£¬Ò²¾ÍÊÇ˵ÔÚ32λ»úÉÏËüÊÇ4¸ö×Ö½Ú£¬¶øÔÚ64λ»úÉÏÊÇ8¸ö×Ö½Ú¡£ l
Ïà¹ØÎĵµ£º
1. structµÄ¾Þ´ó×÷ÓÃ
¡¡¡¡Ãæ¶ÔÒ»¸öÈ˵ĴóÐÍC/C++³ÌÐòʱ£¬Ö»¿´Æä¶ÔstructµÄʹÓÃÇé¿öÎÒÃǾͿÉÒÔ¶ÔÆä±àдÕßµÄ
±à³Ì¾Ñé½øÐÐÆÀ¹À¡£ÒòΪһ¸ö´óÐ͵ÄC/C++³ÌÐò£¬ÊƱØÒªÉ漰һЩ(ÉõÖÁ´óÁ¿)½øÐÐÊý¾Ý×éºÏ
µÄ½á¹¹Ì壬ÕâЩ½á¹¹Ìå¿ÉÒÔ½«Ô±¾ÒâÒåÊôÓÚÒ»¸öÕûÌåµÄÊý¾Ý×éºÏÔÚÒ»Æð¡£´ÓijÖ̶ֳÈÉÏÀ´
˵£¬»á²»»áÓÃstruct£¬ÔõÑùÓÃstructÊÇÇø± ......
http://www.100gps.com/html/index.html ¡£ µØͼÊÇÉϺ£ £¬ËµÃ÷ÉÏÒ»´Î¶¨Î»ÊÇÔÚÉϺ££¬ »òÕßÊÇÉϺ£µÄij¸öÇ¿ÈË×öµÄ µØͼ£¬Õý°æµÄ ¿Á¢µÂµÚÒ»´ÎÓ㬠µØͼӦ¸ÃÊÇÔÚÉîÛÚ cµØͼ£¬Äã¿ÉÒÔÔÚ¹¦ÄÜ——ϵͳ——GPS²ÎÊýÀïÃ棬ÉèÖö˿ڣ¬ Ò»°ã¶¼ÊÇcom2»òÕßÊÇcom4£¬²¨ÌØÂÊ»ù±¾¶¼ÊÇ4800£¬È»ºóÄãÔÙÊÔÊÔÄܶ¨Î»Â𣡠²»ÐУ¬ ......
£¨±¾ÎÄÊÕ¼¯ÖÁÍøÂ磩
1.½éÉÜÒ»ÏÂSTL£¬Ïêϸ˵Ã÷STLÈçºÎʵÏÖvector¡£
STL (±ê׼ģ°æ¿â£¬Standard Template Library)ËüÓÉÈÝÆ÷Ëã·¨µü´úÆ÷×é³É¡£
STLÓÐÒÔϵÄһЩÓŵ㣺
¿ÉÒÔ·½±ãÈÝÒ×µØʵÏÖËÑË÷Êý¾Ý»ò¶ÔÊý¾ÝÅÅÐòµ ......
32)
¡¡¡¡int main()
¡¡¡¡{
¡¡¡¡¡¡int x=3;
¡¡¡¡¡¡printf("%d",x);
¡¡¡¡¡¡return 1;
¡¡¡¡}
¡¡¡¡Îʺ¯Êý¼ÈÈ»²»»á±»ÆäËüº¯Êýµ÷Óã¬ÎªÊ²Ã´Òª·µ»Ø1£¿
¡¡¡¡mianÖУ¬c±ê×¼ÈÏΪ0±íʾ³É¹¦£¬·Ç0±íʾ´íÎó¡£¾ßÌåµÄÖµÊÇijÖоßÌå³ö´íÐÅÏ¢
33) Òª¶Ô¾ø¶ÔµØÖ·0x100000¸³Öµ£¬ÎÒÃÇ¿ÉÒÔÓÃ(unsigned int*)0x100 ......