C/C++ ºê´øÀ´µÄÆæ¼¼ÒùÇÉ
×÷ÕߣºKevin Lynx¡¡À´Ô´£ºC++²©¿Í
ת×Ô:http://www.kuqin.com/language/20080319/4797.html
ÖÚ¶àC++Êé¼®¶¼ÖÒ¸æÎÒÃÇCÓïÑÔºêÊÇÍò¶ñÖ®Ê×£¬µ«ÊÂÇé×ܲ»ÈçÎÒÃÇÏëÏóµÄÄÇô»µ£¬¾ÍÈçͬgotoÒ»Ñù¡£ºêÓÐ
Ò»¸öºÜ´óµÄ×÷Ó㬾ÍÊÇ×Ô¶¯ÎªÎÒÃDzúÉú´úÂë¡£Èç¹û˵ģ°å¿ÉÒÔΪÎÒÃDzúÉú¸÷ÖÖÐͱðµÄ´úÂë(ÐͱðÌæ»»)£¬
ÄÇôºêÆäʵ¿ÉÒÔΪÎÒÃÇÔÚ·ûºÅÉϲúÉúеĴúÂë(¼´·ûºÅÌæ»»¡¢Ôö¼Ó)¡£
¹ØÓÚºêµÄһЩÓï·¨ÎÊÌ⣬¿ÉÒÔÔÚgoogleÉÏÕÒµ½¡£ÏàÐÅÎÒ£¬Äã¶ÔÓÚºêµÄÁ˽â¾ø¶ÔûÄãÏëÏóµÄÄÇô¶à¡£Èç¹ûÄã
»¹²»ÖªµÀ#ºÍ##£¬Ò²²»ÖªµÀprescan£¬ÄÇôÄã¿Ï¶¨¶ÔºêµÄÁ˽ⲻ¹»¡£
ÎÒÉÔ΢½²½âϺêµÄһЩÓï·¨ÎÊÌâ(˵Óï·¨ÎÊÌâËƺõ²»Í×£¬macroÖ»ÓëpreprocessorÓйأ¬¸úÓïÒå·ÖÎöÓÖÎÞ¹Ø)£º
1. ºê¿ÉÒÔÏñº¯ÊýÒ»Ñù±»¶¨Ò壬ÀýÈ磺
#define min(x,y) (x<y?x:y) //ÊÂʵÉÏÕâ¸öºê´æÔÚBUG
µ«ÊÇÔÚʵ¼ÊʹÓÃʱ£¬Ö»Óе±Ð´ÉÏmin()£¬±ØÐë¼ÓÀ¨ºÅ£¬min²Å»á±»×÷ΪºêÕ¹¿ª£¬·ñÔò²»×öÈκδ¦Àí¡£
2. Èç¹ûºêÐèÒª²ÎÊý£¬Äã¿ÉÒÔ²»´«£¬±àÒëÆ÷»á¸øÄ㾯¸æ(ºê²ÎÊý²»¹»)£¬µ«ÊÇÕâ»áµ¼Ö´íÎó¡£ÈçC++Êé¼®ÖÐËùÃè
ÊöµÄ£¬±àÒëÆ÷(Ô¤´¦ÀíÆ÷)¶ÔºêµÄÓï·¨¼ì²é²»¹»£¬ËùÒÔ¸ü¶àµÄ¼ì²éÐÔ¹¤×÷µÃÄã×Ô¼ºÀ´×ö¡£
3. ºÜ¶à³ÌÐòÔ±²»ÖªµÀµÄ#ºÍ##
#·ûºÅ°ÑÒ»¸ö·ûºÅÖ±½Óת»»Îª×Ö·û´®£¬ÀýÈ磺
#define STRING(x) #x
const char *str = STRING( test_string ); strµÄÄÚÈݾÍÊÇ"test_string"£¬Ò²¾ÍÊÇ˵#»á°ÑÆäºóµÄ·ûºÅ
Ö±½Ó¼ÓÉÏË«ÒýºÅ¡£
##·ûºÅ»áÁ¬½ÓÁ½¸ö·ûºÅ£¬´Ó¶ø²úÉúеķûºÅ(´Ê·¨²ã´Î)£¬ÀýÈ磺
#define SIGN( x ) INT_##x
int SIGN( 1 ); ºê±»Õ¹¿ªºó½«³ÉΪ£ºint INT_1;
4. ±ä²Îºê£¬Õâ¸ö±È½Ï¿á£¬ËüʹµÃÄã¿ÉÒÔ¶¨ÒåÀàËƵĺ꣺
#define LOG( format, ... ) printf( format, __VA_ARGS__ )
LOG( "%s %d", str, count );
__VA_ARGS__ÊÇϵͳԤ¶¨Òåºê£¬±»×Ô¶¯Ì滻Ϊ²ÎÊýÁÐ±í¡£
5. µ±Ò»¸öºê×Ô¼ºµ÷ÓÃ×Ô¼ºÊ±£¬»á·¢Éúʲô£¿ÀýÈ磺
#define TEST( x ) ( x + TEST( x ) )
TEST( 1 ); »á·¢Éúʲô£¿ÎªÁË·ÀÖ¹ÎÞÏÞÖƵݹéÕ¹¿ª£¬Óï·¨¹æ¶¨£¬µ±Ò»¸öºêÓöµ½×Ô¼ºÊ±£¬¾ÍÍ£Ö¹Õ¹¿ª£¬Ò²¾ÍÊÇ
˵£¬µ±¶ÔTEST( 1 )½øÐÐÕ¹¿ªÊ±£¬Õ¹¿ª¹ý³ÌÖÐÓÖ·¢ÏÖÁËÒ»¸öTEST£¬ÄÇô¾Í½«Õâ¸öTESTµ±×÷Ò»°ãµÄ·ûºÅ¡£TEST(1)
×îÖÕ±»Õ¹¿ªÎª£º1 + TEST( 1)
Ïà¹ØÎĵµ£º
int arr[]={6,7,8,9,10};
int *ptr=arr;
*(ptr++)+=123;
printf("%d,%d",*ptr,*(++ptr));
´ËÌâ×îºóµÄ½á¹ûÊÇ8£¬8.
Õ§¿´½á¹ûÓ¦¸ÃÊÇ7ºÍ8¡£
ÔÀí£º
ÒòΪËüÃÇ×÷ΪprintfµÄ²ÎÊý£¬º¯Êýprintf´Ó×óÍùÓÒ¶ÁÈ¡£¬È»ºó½«ÏȶÁÈ¡·Åµ½Õ»µ×£¬×îºó¶ÁÈ¡µÄ·ÅÔÚÕ»¶¥£¬´¦ÀíʱºòÊÇ´ÓÕ»¶¥¿ªÊ¼µÄ£¬ËùÓÐÎÒÃÇ¿´¼ûµÄ½á¹ûÊÇ£¬´ÓÓұ߿ªÊ¼´¦ÀíµÄ¡£ ......
1.ÒýÑÔ
¡¡¡¡C++ÓïÑԵĴ´½¨³õÖÔÊÇ“a better C”£¬µ«ÊÇÕâ²¢²»Òâζ×ÅC++ÖÐÀàËÆCÓïÑÔµÄÈ«¾Ö±äÁ¿ºÍº¯ÊýËù²ÉÓõıàÒëºÍÁ¬½Ó·½Ê½ÓëCÓïÑÔÍêÈ«Ïàͬ¡£×÷ΪһÖÖÓûÓëC¼æÈݵÄÓïÑÔ£¬C++±£ÁôÁËÒ»²¿·Ö¹ý³ÌʽÓïÑÔµÄÌص㣨±»ÊÀÈ˳ÆΪ“²»³¹µ×µØÃæÏò¶ÔÏ󔣩£¬Òò¶øËü¿ÉÒÔ¶¨Òå²»ÊôÓÚÈκÎÀàµÄÈ«¾Ö±äÁ¿ºÍº¯Êý¡£µ«ÊÇ£¬C++±Ï¾ ......
http://man.lupaworld.com/content/develop/c&c++/c/c.htm
1. Èç¹û²ÎÊýÊÇÖ¸Õ룬ÇÒ½ö×÷ÊäÈëÓã¬ÔòÓ¦ÔÚÀàÐÍÇ°¼Óconst£¬ÒÔ·ÀÖ¹¸ÃÖ¸ÕëÔÚº¯ÊýÌåÄÚ±»ÒâÍâÐÞ¸Ä
2. ÔÚº¯ÊýÌåµÄ“Èë¿Ú´¦”£¬¶Ô²ÎÊýµÄÓÐЧÐÔ½øÐмì²é
ÔÚº¯ÊýÌåµÄ“³ö¿Ú´¦”£¬¶ÔreturnÓï¾äµÄÕýÈ·ÐÔºÍЧÂʽøÐмì ......
×î½üÔÚ×öÒ»¸öI2C¼üÅ̵ÄLinuxÇý¶¯£¬²Î¿¼ÁËÆäËûоƬµÄһЩ´úÂ룬ÆäÖнÐø·¢ÏÖÓÐЩÈÃÈËÃÔ»óµÄ¶«Î÷£¬°ÑÎÒµÄÃÔ»ó¼°Àí½âÔÚÕâÀï¼ÓÒԼǼ£º
1. i2c_driver½á¹¹ÌåµÄprobe³ÉÔ±µÄÔÐÍ£º
int (*probe)(struct i2c_client *, const struct i2c_device_id *);
¼´£ºprobeº¯Êý±»µ÷ÓÃʱ»á´ÓÉϱߴ«Á½¸ö¸ö²Î ......
C/C++ development with the Eclipse Platform
Pawel Leszek
ÕªÒª:ͨ¹ý±¾ÎÄÄ㽫»ñµÃÈçºÎÔÚEclipseƽ̨ÉÏ¿ª·¢C/C++ÏîÄ¿µÄ×ÜÌåÈÏʶ¡£ËäÈ»EclipseÖ÷Òª±»ÓÃÀ´¿ª·¢JavaÏîÄ¿£¬µ«ËüµÄ¿ò¼ÜʹµÃËüºÜÈÝÒ×ʵÏÖ¶ÔÆäËû¿ª·¢ÓïÑÔµÄÖ§³Ö¡£ÔÚÕâƪÎÄÕÂÀÄ㽫ѧ»áÈçºÎʹÓÃCDT(C/C++ Development Toolkit)£¬Ò»¸öÔÚEclipseƽ̨ÉÏ×î ......