extern "C" Ïê½â
extern "C" Ïê½â
ÔÚC++ÖУ¬ÎªÁËÖ§³ÖÖØÔØ»úÖÆ£¬ÔÚ±àÒëÉú³É»ã±à´úÂëʱ£¬º¯ÊýµÄÃû×ÖÒª¼ÓÈ뺯ÊýµÄ²ÎÊýÀàÐÍ»òÕß·µ»ØÖµÀàÐ͵ÈÐÅÏ¢
ÔÚCÖУ¬ÒòûÓÐÖØÔØ»úÖÆ£¬±àÒëºóµÄ´úÂëÖ»ÊǼòµ¥µÄº¯ÊýÃû×Ö¶øÒÑ£¬²»¼ÓÈëÆäËûµÄÐÅÏ¢
1. ²»¼ÓÈëextern "C"
testexternc.cpp
int mytest(void)
{
int a=10,b=20;
int c=a+b;
return c;
}
Command: g++ -S testexternc.cpp»òÕßgcc -S testexternc.cpp
Generated file: testexternc.s
.file "testexternc.cpp"
.text
.align 2
.globl _Z6mytestv
.type _Z6mytestv, @function
_Z6mytestv:
.LFB2:
pushl %ebp
.LCFI0:
movl %esp, %ebp
.LCFI1:
subl $16, %esp
.LCFI2:
movl $10, -12(%ebp)
movl $20, -8(%ebp)
movl -8(%ebp), %eax
addl -12(%ebp), %eax
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
leave
ret
.LFE2:
.size _Z6mytestv, .-_Z6mytestv
.globl __gxx_personality_v0
Ïà¹ØÎĵµ£º
C³ÌÐòÊÇÓÉÒ»×é»òÊDZäÁ¿»òÊǺ¯ÊýµÄÍⲿ¶ÔÏó×é³ÉµÄ¡£ º¯ÊýÊÇÒ»¸ö×ÔÎÒ°üº¬µÄÍê³ÉÒ»¶¨Ïà¹Ø¹¦ÄܵÄÖ´ÐдúÂë¶Î¡£ÏÂÃæС±àºÍ´ó¼Ò·ÖÏíÏÂCÓïÑÔÖеĺ¯Êý¡£
1. setvectº¯Êý
setvectº¯ÊýµÄ¹¦ÄÜÊÇÉèÖÃÖжÏʸÁ¿Èë¿Ú£¬ÆäÓ÷¨Îª£ºvoid setvect(int intr_num, void interrupt(*isr)());³ÌÐòʵÀýÈçÏ£º
#include <st ......
ʹÓÃKeil Cµ÷ÊÔijϵͳʱ»ýÀÛµÄһЩ¾Ñé
1¡¢ÔÚWindows2000ÏÂÃ棬ÎÒÃÇ¿ÉÒÔ°Ñ×ÖÌåÉèÖÃΪCourier£¬ÕâÑù¾Í¿ÉÒÔÏÔʾÕý³£¡£
2¡¢µ±Ê¹ÓÃÓÐƬÍâÄÚ´æµÄMCU£¨ÈçW77E58£¬ËüÓÐ1KƬÍâÄڴ棩µÄʱºò£¬¿Ï¶¨ÒªÉèÖñê־룬²¢ÇÒ±àÒ뷽ʽҪѡÔñ´óģʽ£¬·ñÔò»á³ö´í¡£
3¡¢µ±Ê¹ÓÃKeil C¸ú×Ù³ÌÐòÔËÐÐ״̬µÄʱºò£¬Òª°ÑÒýÆðWarningµÄÓï¾äÆÁ±Î£ ......
½ñÌìÒª±à¸ö×î¼òµ¥µÄ"hello world"µÄC³ÌÐò£¬ËãÊdzõ²½¸ÐÊÜÏÂLinuxÖеıà³Ì»·¾³£¬Éæ¼°ÒÔÏÂ3¸ö²½Ö裺
1. ÏÈÔÚ"vim"Àï±àдԴÎļþ£»
2. È»ºóÔÙÓÃ"gcc"±àÒëÉú³É"hello"µÄ¿ÉÖ´ÐÐÎļþ£»
3. ÔËÐÐ"hello"£¬¿´¿´Ð§¹û¡£
ÄÇô¿ªÊ¼°É£¡
1. vim
vim hello.c
i
#include <stdio.h>
int
main (void)
{
printf ("hello.\n" ......
º¯ÊýÃûÓ뺯ÊýÖ¸Õë
º¯Êý´æ·ÅÔÚÄÚ´æµÄ´úÂëÇøÓòÄÚ£¬ËüÃÇͬÑùÓеØÖ·£¬ÎÒÃÇÈçºÎÄÜ»ñµÃº¯ÊýµÄµØÖ·ÄØ£¿
Èç¹ûÎÒÃÇÓÐÒ»¸öint test(int a)µÄº¯Êý£¬ÄÇô£¬ËüµÄµØÖ·¾ÍÊǺ¯ÊýµÄÃû×Ö£¬ÕâÒ»µãÈçͬÊý×éÒ»Ñù£¬Êý×éµÄÃû×Ö¾ÍÊÇÊý×éµÄÆðʼµØÖ·¡£
Ò» ͨ³£µÄº¯Êýµ÷ÓÃ
Ò»¸öͨ³£µÄº¯Êýµ÷ÓõÄÀý×Ó ......
CµÄËÄÖÖ´æ´¢ÀàÏÞ¶¨·û£º
extern:Íⲿ±äÁ¿
static £º¾²Ì¬
register£º´æ´¢Æ÷
auto£º×Ô¶¯¡¡
¾²Ì¬¾Ö²¿±äÁ¿£º
´æ´¢ÇøºÍÈ«¾Ö±äÁ¿ÊÇÒ»ÑùµÄ¡£¾²Ì¬¾Ö²¿ºÍÈ«¾Ö±äÁ¿¼äµÄÖ÷ÒªÇø±ðÊÇ£º¾²Ì¬¾Ö²¿±äÁ¿½ö¶ÔËüÔÚÆäÖÐÉùÃ÷µÄ¿éÊÇ¿ÉÖªµÄ¡£
¾²Ì¬È«¾Ö±äÁ¿£º
¸æËß±àÒëÆ÷´´½¨Ò»¸ö½öÔÚÉùÃ÷ËüµÄÎļþÖпÉÖªµÄÈ«¾Ö±äÁ¿¡£ÕâÒâζ×Å£º¼´Ê¹±äÁ¿Ê ......