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++ ³ÌÐòʹÓá£
Ïà¹ØÎĵµ£º
stroul£¬
strdup
snprintf()
atio
CÖг£ÓÃ×Ö·û´®²Ù×÷º¯Êý
#include <string.h>
size_t strlen(const char *s) ²âÁ¿×Ö·û´®³¤¶ÈsµÄʵ¼Ê³¤¶È¡£
ÀýÈçs[20]="abc",ÄÇôstrlen(s)µÄ½á¹ûÊÇ3£¬¶ø²»ÊÇ20.Õâ¾ÍÊÇʵ¼Ê³¤¶È
char *strcat(const char *s1, const *s2) ......
µÚÒ»Õ CÓïÑÔ¸ÅÊö
²»ÒªÌÖÂÛΪʲôҪѧϰCÓïÑÔµÄÎÊÌ⣬CÓïÑÔ×ÔÓÐËü×Ô¼º¶ÀÌØµÄÆøÏ¢£¡
Ò»¡¢CÓïÑÔµÄÀúÊ·
CÓïÑÔÊÇ1972ÄêÖÁ1973Äê¼ä£¬ÔÚÃÀ¹úµÄ±´¶ûʵÑéÊÒ( Bell Laboratories )ÓÉDennis M. RitchieÒ»¸öÈË¿ª·¢³öÀ´µÄÒ»ÖÖÏà¶Ô±È½ÏеijÌÐòÉè¼ÆÓïÑÔ¡£
1960Ä꣬³öÏÖµÄALGOL 60 (Ò²³Æ A ÓïÑ ......
windows7 + ubuntu9.10Ë«Æô¶¯,Õâ¸öÓÐÌ«¶àµÄÌû×ÓÁË,²»¹ýÕâ´ÎµÄÇé¿ö±È½Ï¸´ÔÓ.
ÏÈ×°µÄWIN7,ºó×°UBUNTU,ûÓÐÈκÎÎÊÌâ.GRUBË«Æô¶¯.
ºóÀ´ÒòΪһ¸öÇé¿ö,ҪװXP,°ÑWIN7×öÁË ghost.×°ÍêXP,GRUBµ±È»Ã»ÓÐÁË,ÓÚÊÇÓÃubuntuÆô¶¯ÅÌÐÞ¸´.
ËäÈ»Æô¶¯²Ëµ¥³öÀ´ÁË,µ«Ö»ÄܽøÐÐubuntu,½øÈëwindowsµÄʱºò¾ÍÌáʾerror:cannot get C/H/S value ......
ÍøÉÏÓÐºÃ¶àÆªÎÄÕ½²ÈçºÎÅäÖÃ.vimrcÎļþÀ´ÊµÏÖVIMÀïÒ»¼ü±àÒ룬¿´ÁËһϱȽϸ´ÔÓ¡£ÎÒÒ»°ãûÓÐʲô´óµÄ³ÌÐòҪд£¬Ò»°ãµÄС³ÌÐòµ¥¸öCÎļþ¾Í¸ãµàÁË£¬ËùÒÔ¼ò»¯ÁËÒ»ÏÂÍøÉϵÄÅäÖã¬ÔÚ.vimrcÀï¼ÓÉÏÁ½ÐоÍÂú×ãÎÒµÄÐèÇóÁË¡£
set makeprg=gcc\ -Wall\ -o\ %<\ %
map <F7> :make<CR ......
As is Known to us,the function Main is the entry point of all programs.Therefore, we are usually neglecting all that we don't do,which makes us not understanding it more clearly.Now there is a sample arm program which will provide something that opration system usually do.
asm:
&nb ......