extern "C"
extern "C"
¡¡¡¡extern "C" °üº¬Ë«Öغ¬Ò壬´Ó×ÖÃæÉϼ´¿ÉµÃµ½£ºÊ×ÏÈ£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“extern”µÄ£»Æä´Î£¬±»ËüÐÞÊεÄÄ¿±êÊÇ“C”µÄ¡£ÈÃÎÒÃÇÀ´Ïêϸ½â¶ÁÕâÁ½Öغ¬Òå¡£
¡¡¡¡£¨1£© ±»extern "C"ÏÞ¶¨µÄº¯Êý»ò±äÁ¿ÊÇexternÀàÐ͵ģ»
¡¡¡¡externÊÇC/C++ÓïÑÔÖбíÃ÷º¯ÊýºÍÈ«¾Ö±äÁ¿×÷Ó÷¶Î§£¨¿É¼ûÐÔ£©µÄ¹Ø¼ü×Ö£¬¸Ã¹Ø¼ü×Ö¸æËß±àÒëÆ÷£¬ÆäÉùÃ÷µÄº¯ÊýºÍ±äÁ¿¿ÉÒÔÔÚ±¾Ä£¿é»òÆäËüÄ£¿éÖÐʹÓ᣼Çס£¬ÏÂÁÐÓï¾ä£º
¡¡¡¡extern int a;
¡¡¡¡½ö½öÊÇÒ»¸ö±äÁ¿µÄÉùÃ÷£¬Æä²¢²»ÊÇÔÚ¶¨Òå±äÁ¿a£¬²¢Î´Îªa·ÖÅäÄÚ´æ¿Õ¼ä¡£±äÁ¿aÔÚËùÓÐÄ£¿éÖÐ×÷ΪһÖÖÈ«¾Ö±äÁ¿Ö»Äܱ»¶¨ÒåÒ»´Î£¬·ñÔò»á³öÏÖÁ¬½Ó´íÎó¡£
¡¡¡¡Í¨³££¬ÔÚÄ£¿éµÄÍ·ÎļþÖжԱ¾Ä£¿éÌṩ¸øÆäËüÄ£¿éÒýÓõĺ¯ÊýºÍÈ«¾Ö±äÁ¿ÒԹؼü×ÖexternÉù
Ã÷¡£ÀýÈ磬Èç¹ûÄ£¿éBÓûÒýÓøÃÄ£¿éAÖж¨ÒåµÄÈ«¾Ö±äÁ¿ºÍº¯ÊýʱֻÐè°üº¬Ä£¿éAµÄÍ·Îļþ¼´¿É¡£ÕâÑù£¬Ä£¿éBÖе÷ÓÃÄ£¿éAÖеĺ¯Êýʱ£¬ÔÚ±àÒë½×¶Î£¬Ä£¿éBËäÈ»
ÕÒ²»µ½¸Ãº¯Êý£¬µ«ÊDz¢²»»á±¨´í£»Ëü»áÔÚÁ¬½Ó½×¶ÎÖдÓÄ£¿éA±àÒëÉú³ÉµÄÄ¿±ê´úÂëÖÐÕÒµ½´Ëº¯Êý¡£
¡¡¡¡Óëextern¶ÔÓ¦µÄ¹Ø¼ü×ÖÊÇstatic£¬±»ËüÐÞÊεÄÈ«¾Ö±äÁ¿ºÍº¯ÊýÖ»ÄÜÔÚ±¾Ä£¿éÖÐʹÓá£Òò´Ë£¬Ò»¸öº¯Êý»ò±äÁ¿Ö»¿ÉÄܱ»±¾Ä£¿éʹÓÃʱ£¬Æä²»¿ÉÄܱ»extern “C”ÐÞÊΡ£
¡¡¡¡£¨2£© ±»extern "C"ÐÞÊεıäÁ¿ºÍº¯ÊýÊÇ°´ÕÕCÓïÑÔ·½Ê½±àÒëºÍÁ¬½ÓµÄ£»
¡¡¡¡Î´¼Óextern “C”ÉùÃ÷ʱµÄ±àÒ뷽ʽ
¡¡¡¡Ê×ÏÈ¿´¿´C++ÖжÔÀàËÆCµÄº¯ÊýÊÇÔõÑù±àÒëµÄ¡£
¡¡¡¡×÷ΪһÖÖÃæÏò¶ÔÏóµÄÓïÑÔ£¬C++Ö§³Öº¯ÊýÖØÔØ£¬¶ø¹ý³ÌʽÓïÑÔCÔò²»Ö§³Ö¡£º¯Êý±»C++±àÒëºóÔÚ·ûºÅ¿âÖеÄÃû×ÖÓëCÓïÑԵIJ»Í¬¡£ÀýÈ磬¼ÙÉèij¸öº¯ÊýµÄÔÐÍΪ£º
¡¡¡¡void foo( int x, int y );
¡¡¡¡¸Ãº¯Êý±»C±àÒëÆ÷±àÒëºóÔÚ·ûºÅ¿âÖеÄÃû×ÖΪ_foo£¬¶øC++±àÒëÆ÷Ôò»á²úÉúÏñ
_foo_int_intÖ®ÀàµÄÃû×Ö£¨²»Í¬µÄ±àÒëÆ÷¿ÉÄÜÉú³ÉµÄÃû×Ö²»Í¬£¬µ«ÊǶ¼²ÉÓÃÁËÏàͬµÄ»úÖÆ£¬Éú³ÉµÄÐÂÃû×Ö³ÆΪ“mangledname”£©¡£
_foo_int_intÕâÑùµÄÃû×Ö°üº¬Á˺¯ÊýÃû¡¢º¯Êý²ÎÊýÊýÁ¿¼°ÀàÐÍÐÅÏ¢£¬C++¾ÍÊÇ¿¿ÕâÖÖ»úÖÆÀ´ÊµÏÖº¯ÊýÖØÔصġ£ÀýÈ磬ÔÚC++ÖУ¬º¯Êývoid
foo( int x, int y )Óëvoid foo( int x, float
y)±àÒëÉú³ÉµÄ·ûºÅÊDz»ÏàͬµÄ£¬ºóÕßΪ_foo_int_float¡£
¡¡¡¡Í¬ÑùµØ£¬C++ÖеıäÁ¿³ýÖ§³Ö¾Ö²¿±äÁ¿Í⣬»¹Ö§³ÖÀà³ÉÔ±±äÁ¿ºÍÈ«¾Ö±äÁ¿¡£Óû§Ëù±àд³ÌÐòµÄÀà³É
Ô±±äÁ¿¿ÉÄÜÓëÈ«¾Ö±äÁ¿Í¬Ãû£¬ÎÒÃÇÒÔ"."À´Çø·Ö¡£¶ø±¾ÖÊÉÏ£¬±àÒëÆ÷ÔÚ½øÐбàÒëʱ£¬Ó
Ïà¹ØÎĵµ£º
1¡¢int 4×Ö½Ú
long 8×Ö½Ú
float 4×Ö½Ú
double 8×Ö½Ú
long double 16×Ö½Ú
2¡¢Ò»¸ö×Ö·û±äÁ¿Ö»ÄÜ´æ·ÅÒ»¸ö×Ö·û¡¢Ò»¸ö×Ö½Ú´æ·ÅÒ»¸ö×Ö½Ú
char c;
c = 'a'; c = '\034' ......
[This was posted to comp.lang.c by its author, David Anderson, on 1994-05-06.]
The ``Clockwise/Spiral Rule''
By David Anderson
There is a technique known as the ``Clockwise/Spiral Rule'' which enables any C programmer to parse in their head any C declaration!
There are three simple steps to fo ......
»Ø¹Ë֮ǰµÄƪ·ù£¬CÓïÑÔµÄÖ÷Ì岿·Ö»ù±¾ÒѾ½éÉÜÍêÁË¡£Ö®ËùÒÔûÓнéÉÜC++µÄÏà¹ØÌØÐÔÊÇÒòΪÔÚ֮ǰµÄÎÄÕÂÖÐCºÍC++ÔÚÕâЩ·½Ã涼Óй²ÐÔ£¬ËùÒÔÔÚÃæÏò¶ÔÏó֮ǰ¡£ÎÒÃÇÏÈ°ÑÕâЩ¹²ÐÔ¸ø½éÉÜÍê¡£Ò²¾ÍÊÇ˵ÔÚ½éÉÜÃæÏò¶ÔÏó֮ǰ£¬ËùÓеÄÎÄÕ¶¼ÊÇCC++Öж¼ÄÜʹÓõġ£´ÓÕâµãÉÏÀ´¿´£¬ÏÖÔÚÕý¼«Á¦·Ü¶·ÓÚC++Õ½ÏßÉϵijõѧÕß»¹ÊǺÜÓÐÓô¦µÄ¡£
±¾Æª¼ÌÐ ......
ÏÂÃæÓõ½µÄ·½·¨½ÐշתÏà³ý·¨£¬¾ß×ö²½ÖèÈçÏÂ
ÏÈÓÃСµÄÒ»¸öÊý³ý´óµÄÒ»¸öÊý£¬µÃµÚÒ»¸öÓàÊý£»
ÔÙÓõÚÒ»¸öÓàÊý³ýСµÄÒ»¸öÊý£¬µÃµÚ¶þ¸öÓàÊý£»
ÓÖÓõڶþ¸öÓàÊý³ýµÚÒ»¸öÓàÊý£¬µÃµÚÈý¸öÓàÊý£» &nb ......