extern C µÄ×÷ÓÃ
extern "C" ÊÇ C++ ±àÒëÆ÷Ö§³ÖµÄÒ»ÖÖÁ´½Óָʾ·û£¨linkage directive£©£¬Ëü±íʾÓÉÆäÉùÃ÷µÄº¯ÊýʹÓà C ÓïÑԵķ½Ê½±àÒëºÍÁ´½Ó¡£
C ºÍ C++ ¶Ôº¯Êý±àÒëºó²úÉúµÄ·ûºÅÃûÊDz»Ò»ÑùµÄ¡£¼ÙÉèÒ»¸öº¯ÊýµÄÔÐÍΪ:
void foo(int x, int y);
ÓÉ C ±àÒëÆ÷±àÒëºó²úÉúµÄ·ûºÅÃûΪ _foo£¬¶ø C++ ÓÉÓÚÖ§³ÖÖØÔصÄÐèÒª£¬±àÒëºóµÄ·ûºÅÃûΪ _foo_int_int ¡£µ±¸Ãº¯ÊýÓÉ extern "C" ÐÞÊκó£¬C++ ±àÒëÆ÷»á°´ C µÄ¹æÔò°ÑËü±àÒë³É _foo¡£
extern "C" µÄÓ÷¨ÓÐÁ½ÖÖ¸ñʽ£º
µ¥Ò»Óï¾äÐÎʽµÄÁ´½Óָʾ·û£º
extern "C" void foo(int, int);
¸´ºÏÓï¾äÐÎʽµÄÁ´½Óָʾ·û£º
extern "C" {
void foo(int, int);
void bar(int, int);
}
extern "C" µäÐ͵ÄÓ÷¨ÊÇÀàËÆÏÂÃæµÄ¸ñʽ°üº¬ÔÚÒ»¸öÍ·ÎļþÖУº
#ifdef __cplusplus
extern “C” {
#endif
void fun(void);
… …
#ifdef __cplusplus
}
#endif
ÕâÑùÉùÃ÷µÄÍ·ÎļþÓÐÒÔÏÂÌص㣺
1. ÄÜͬʱ֧³Ö C »ò C++ ±àÒëÆ÷¡££¨C ±àÒëÆ÷²»Ö§³Ö extern "C" ·ûºÅ£¬ËùÒÔÓÉ __cplusplus ºê±£»¤£©
2. Í·ÎļþÖÐÉùÃ÷µÄº¯Êý¶¼°´ÕÕ C µÄ·½Ê½±àÒëºÍÁ´½Ó¡£
ÓÉÉÏÃæÁ½¸öÌصã¿ÉÒÔ±£Ö¤Ê¹ÓøÃÍ·ÎļþµÄ C »ò C++ ³ÌÐò¶¼Í³Ò»°´ÕÕ C µÄ·½Ê½ÕÒµ½±àÒëºóµÄº¯Êý·ûºÅ£¬¶øÎÞÂÛÕâ¸öº¯Êý֮ǰÊÇÓÉ C »ò C++ ±àÒëµÄ¡£
ʹÓÃÀý×Ó
Linux ÖÐËùÓеÄϵͳͷÎļþ¡¢±ê×¼ C Í·ÎļþµÄ¿ªÍ·ºÍ½áβ²¿·Ö¶¼»á·Ö±ð°üº¬ __BEGIN_DECLS ºÍ __END_DECLS Á½¸öºê¡£ÕâÁ½¸öºêÊÇÔÚ sys/cdefs.h Öж¨ÒåµÄ£¬ÏµÍ³±ê׼ͷÎļþÒ»°ã¶¼»áͨ¹ý features.h ¼ä½Ó°üº¬¡£ÏÂÃæÊÇÕâÁ½¸öºêµÄ¶¨Ò壺
/* C++ needs to know that types and declarations are C, not C++. */
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS
# define __END_DECLS
#endif
Ö»ÒªÄÜÀí½âÇ°ÃæµÄ·¶ÀýÍ·Îļþ£¬¾ÍÄÜÃ÷°×ϵͳͷÎļþÒªÕâÑùÉè¼ÆµÄÒâͼÁË£º¼´ÄÜÈà C++ ³ÌÐò°´ÕÕ C µÄ·½Ê½Á´½ÓºÍʹÓà C º¯Êý¿â¡£
ͬÑùµÄʹÓÃÔÀí»¹¿ÉÒÔÔÚ glib ¿âÖп´µ½¡£ËùÓÐµÄ glib Í·Îļþ¶¼»á°üº¬Ò»¶Ô G_BEGIN_DECLS
ºÍ G_END_DECLS
ºê£¬ËüÃÇÊÇÔÚ glib/gmacros.h Öж¨ÒåµÄ¡£ÕâÑù glib ¿âÒ²Äܱ» C++ ³ÌÐòʹÓá£
Ïà¹ØÎĵµ£º
Ôø¾Åöµ½¹ýÈÃÄãÃԻ󲻽⡢ÀàËÆÓÚint * (* (*fp1) (int) )
[10];ÕâÑùµÄ±äÁ¿ÉùÃ÷Â𣿱¾ÎĽ«ÓÉÒ×µ½ÄÑ£¬Ò»²½Ò»²½½Ì»áÄãÈçºÎÀí½âÕâÖÖ¸´ÔÓµÄC/C++ÉùÃ÷£ºÎÒÃÇ
½«´ÓÿÌ춼ÄÜÅöµ½µÄ½Ï¼òµ¥µÄÉùÃ÷ÈëÊÖ£¬È»ºóÖð²½¼ÓÈëconstÐÞÊÎ
·ûºÍtypedef£¬»¹Óк¯ÊýÖ¸Õ룬×îºó½éÉÜÒ»¸öÄܹ»ÈÃÄã׼ȷµØÀí½âÈκÎC/C++ ......
1£®¸ÅÄî
ÔÚC/C++ÖУ¬¶Ô×Ö·û´®µÄ²Ù×÷ÓкܶàÖµµÃ×¢ÒâµÄÎÊÌ⣬ͬÑù£¬C/C++¶Ôʱ¼äµÄ²Ù×÷Ò²ÓÐÐí¶àÖµµÃ´ó¼Ò×¢ÒâµÄµØ·½¡£×î½ü£¬ÔÚ¼¼ÊõȺÖÐÓкܶàÍøÓÑÒ²¶à´ÎÎʵ½¹ýC++ÓïÑÔÖжÔʱ¼äµÄ²Ù×÷¡¢»ñÈ¡ºÍÏÔʾµÈµÈµÄÎÊÌâ¡£ÏÂÃ棬ÔÚÕâƪÎÄÕÂÖУ¬±ÊÕß½«Ö÷Òª½éÉÜÔÚC/C++ÖÐʱ¼äºÍÈÕÆÚµÄʹÓ÷½·¨. ......
B/S½á¹¹£¨Browser/Server½á¹¹£©½á¹¹¼´ä¯ÀÀÆ÷ºÍ·þÎñÆ÷½á¹¹¡£ËüÊÇËæ×ÅInternet¼¼ÊõµÄÐËÆ𣬶ÔC/S½á¹¹µÄÒ»Öֱ仯»òÕ߸ĽøµÄ½á¹¹¡£ÔÚÕâÖֽṹÏ£¬Óû§¹¤×÷½çÃæÊÇͨ¹ýWWWä¯ÀÀÆ÷À´ÊµÏÖ£¬¼«ÉÙ²¿·ÖÊÂÎñÂß¼ÔÚÇ°¶Ë£¨Browser£©ÊµÏÖ£¬µ«ÊÇÖ÷ÒªÊÂÎñÂß¼ÔÚ·þÎñÆ÷¶Ë£¨Server£©ÊµÏÖ£¬ÐγÉËùνÈý²ã3-tier½á¹¹¡£ÕâÑù¾Í´ó´ó¼ò»¯ÁË¿Í»§¶ËµçÄÔÔØ ......
cѧµÄÈ˺ܶࡣµ«Ê®Ö®°Ë¾ÅÊÇ°ëÍ°Ë®¡£»òÕßдµÃºÜËÀ¡£Ò²ÐíÎÒÕâ»°ÓеãÆ«¼¤¡£µ«ÊÇÎÒ¸ø³öÒ»¸ö±ê×¼°É¡£ÄãÄÜд³öÏñlinuxÄں˴úÂëÕâÑùµÄ´úÂëÂð£¿ÆäʵÈκÎÒ»ÃÅÓïÑԵľ«Ë裬ÔÚÓÚÔËÓá£ËùÒÔÔÚѧϰ֮ǰ×îºÃÎÊÒ»ÎÊÎÒΪʲҪѧÕâÃÅÓïÑÔ¡£Èç¹ûÊÇΪѧ¶øѧ£¬Ñ§µ½×îºóÓÖÊÇ°ëÍ°Ë®¡£»¹ÕæµÄ²»È翴С˵À´µÃ´Ì¼¤¡£Ã»ÓÐÄ¿µÄ¸ÉÊÂÇ飬±¾Éí¾ÍÊÇÒ»ÖÖÀË·Ñ¡£ ......
תÔØ×Ô£ºhttp://www.cnblogs.com/chio/archive/2007/11/26/972152.html
CRTÔÏÈÊÇÖ¸Microsoft¿ª·¢µÄC Runtime Library£¬ÓÃÓÚ²Ù×÷ϵͳµÄ¿ª·¢¼°ÔËÐС£ºóÀ´ÔÚ´Ë»ù´¡ÉÏ¿ª·¢ÁËC++ Runtime Library£¬ËùÒÔÏÖÔÚCRTÊÇÖ¸Microsoft¿ª·¢µÄC/C++ Runtime Library¡£ÔÚVCµÄCRT/SRCĿ¼Ï£¬¿ÉÒÔ¿´µ½CRTµÄÔ´Â룬²»½öÓÐCµÄ£¬Ò²ÓÐC++µ ......