Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

extern c×÷ÓÃ

Á´½Óָʾ·ûextern C
Èç¹û³ÌÐòԱϣÍûµ÷ÓÃÆäËû³ÌÐòÉè¼ÆÓïÑÔÓÈÆäÊÇC дµÄº¯ÊýÄÇôµ÷Óú¯Êýʱ±ØÐë
¸æËß±àÒëÆ÷ʹÓò»Í¬µÄÒªÇóÀýÈçµ±ÕâÑùµÄº¯Êý±»µ÷ÓÃʱº¯ÊýÃû»ò²ÎÊýÅÅÁеÄ˳Ðò¿ÉÄÜ
²»Í¬ÎÞÂÛÊÇC++º¯Êýµ÷ÓÃËü»¹ÊÇÓÃÆäËûÓïÑÔдµÄº¯Êýµ÷ÓÃËü
³ÌÐòÔ±ÓÃÁ´½Óָʾ·ûlinkage directive ¸æËß±àÒëÆ÷¸Ãº¯ÊýÊÇÓÃÆäËûµÄ³ÌÐòÉè¼ÆÓïÑÔ
±àдµÄÁ´½Óָʾ·ûÓÐÁ½ÖÖÐÎʽ¼È¿ÉÒÔÊǵ¥Ò»Óï¾äsingle statement ÐÎʽҲ¿ÉÒÔÊǸ´
ºÏÓï¾äcompound statement ÐÎʽ
// µ¥Ò»Óï¾äÐÎʽµÄÁ´½Óָʾ·û
extern "C" void exit(int);
// ¸´ºÏÓï¾äÐÎʽµÄÁ´½Óָʾ·û
extern "C" {
int printf( const char* ... );
int scanf( const char* ... );
}
// ¸´ºÏÓï¾äÐÎʽµÄÁ´½Óָʾ·û
extern "C" {
#include <cmath>
}
Á´½Óָʾ·ûµÄµÚÒ»ÖÖÐÎʽÓɹؼü×Öextern ºó¸úÒ»¸ö×Ö·û´®³£Á¿ÒÔ¼°Ò»¸öÆÕͨµÄº¯Êý
ÉùÃ÷¹¹³ÉËäÈ»º¯ÊýÊÇÓÃÁíÍâÒ»ÖÖÓïÑÔ±àдµÄµ«µ÷ÓÃËüÈÔÈ»ÐèÒªÀàÐͼì²éÀýÈç±àÒëÆ÷
»á¼ì²é´«µÝ¸øº¯Êýexit()µÄʵ²ÎµÄÀàÐÍÊÇ·ñÊÇint »òÕßÄܹ»ÒþʽµØת»»³Éint ÐÍ
¶à¸öº¯ÊýÉùÃ÷¿ÉÒÔÓû¨À¨ºÅ°üº¬ÔÚÁ´½Óָʾ·û¸´ºÏÓï¾äÖÐÕâÊÇÁ´½Óָʾ·ûµÄµÚ¶þÖÖÐÎ
ʽ»¨Õкű»ÓÃ×÷·Ö¸î·û±íʾÁ´½Óָʾ·ûÓ¦ÓÃÔÚÄÄЩÉùÃ÷ÉÏÔÚÆäËûÒâÒåÉϸû¨À¨ºÅ±»ºö
ÂÔËùÒÔÔÚ»¨À¨ºÅÖÐÉùÃ÷µÄº¯ÊýÃû¶ÔÍâÊǿɼûµÄ¾ÍºÃÏñº¯ÊýÊÇÔÚ¸´ºÏÓï¾äÍâÉùÃ÷µÄÒ»Ñù
ÀýÈçÔÚÇ°ÃæµÄÀý×ÓÖи´ºÏÓï¾äextern "C"±íʾº¯Êýprintf()ºÍscanf()ÊÇÔÚC ÓïÑÔÖÐдµÄ
º¯ÊýÒò´ËÕâ¸öÉùÃ÷µÄÒâÒå¾ÍÈçͬprintf()ºÍscanf()ÊÇÔÚextern "C"¸´ºÏÓï¾äÍâÃæÉùÃ÷µÄ
Ò»Ñù
µ±¸´ºÏÓï¾äÁ´½Óָʾ·ûµÄÀ¨ºÅÖк¬ÓÐ#include ʱÔÚÍ·ÎļþÖеĺ¯ÊýÉùÃ÷¶¼±»¼Ù¶¨ÊÇÓÃ
Á´½Óָʾ·ûµÄ³ÌÐòÉè¼ÆÓïÑÔËùдµÄÔÚÇ°ÃæµÄÀý×ÓÖÐÔÚÍ·Îļþ<cmath>ÖÐÉùÃ÷µÄº¯Êý¶¼ÊÇC
º¯Êý
Á´½Óָʾ·û²»ÄܳöÏÖÔÚº¯ÊýÌåÖÐÏÂÁдúÂë¶Î½«»áµ¼Ö±àÒë´íÎó
int main()
{
// ´íÎó: Á´½Óָʾ·û²»ÄܳöÏÖÔÚº¯ÊýÄÚ
extern "C" double sqrt( double );
305 µÚÆßÕº¯Êý
double getValue(); //ok
double result = sqrt ( getValue() );
//...
return 0;
}
Èç¹û°ÑÁ´½Óָʾ·ûÒƵ½º¯ÊýÌåÍâ³ÌÐò±àÒ뽫ÎÞ´íÎó
extern "C" double sqrt( double );
int main()
{
double getValue(); //ok
double result = sqrt ( getValue() );
//...
return 0;
}
µ«ÊÇ°ÑÁ´½Óָʾ·û·ÅÔÚÍ·ÎļþÖиüºÏÊÊÔÚÄÇÀﺯÊýÉùÃ÷ÃèÊöÁ˺¯ÊýµÄ½Ó¿ÚËùÊô
Èç¹ûÎÒÃÇÏ£ÍûC++º¯ÊýÄ


Ïà¹ØÎĵµ£º

C/C++ ÃæÊÔÌâ

µÚÒ»Ì⣺
ÏÂÃæ³ÌÐòµÄÊä³ö½á¹û£¿
#include <stdio.h>
#include <iostream>
void main()
{
char str1[] = "";
char str2[] = "";
const char str3[] = "abc";
const char str4[] = "abc";
const char* str5 = "abc";
const char* str6 = "a ......

×Ô¼ºÊÜÁ˵ã´Ì¼¤ JavaÄܹ»Ìæ´úCÓïÑÔÂð£¿


ÎÒ²»ÖªµÀÕâƪÎÄÕµÄ×÷ÕßÊÇË­£¬µ«ÎÒÖªµÀ£¬Ëû¶ÔjavaÓÐÒ»ÖÖºÜÉîµÄÀí½â£¬ÆäʵÎÄÕÂÖв¢Ã»ÓÐÌåÏÖ³ö×÷Õ߶Ôjava¼¼ÊõÉî²ãÀí½â£¬µ«ÊÇ´ÓÎÄÖеÄÿһ¾ä»°ÖУ¬ÎÒ¸ÐÊܵ½ÁËһЩ¶«Î÷¡£ÕâÊÇһƪºÜºÃµÄÎÄÕ£¬Ò²¿ÉÒÔ°ïÖúºÜ¶àÈËÃÔãµÄÈ˽â¾öÎÊÌâ¡£´øÀ´ºÍ´ó¼Ò·ÖÏíһϡ£
Ç°²»¾ÃCSDN¿¯µÇÁËһƪ¡¶CÓïÑÔÒѾ­ËÀÁË¡·µÄÎÄÕ£¬ÒýÆðÁËһЩÕùÂÛ¡£ÆäʵÄÇÆ ......

MISRA C £ºÈÃǶÈëʽϵͳ¸ü¼Ó°²È«¿É¿¿µÄһЩ¹Ø¼ü¹æÔò

ת×Ô£ºhttp://www.bmrtech.com/article/2008/081126.htm
    ûÈËÄÜ·ñÈÏǶÈëʽӦÓÃÕý±äµÃÔ½À´Ô½Æձ顣µ«ÊÇ£¬µ±ÏµÍ³Ô½À´Ô½¸´ÔÓ£¬¶øÎÒÃǸ³ÓèϵͳԽÀ´Ô½¶àµÄÔðÈεÄʱºò£¬ÎÒÃǽ«±ØÐëÃæ¶ÔһЩÖØÒªÎÊÌâ¡£ÆäÖÐ×îÖØÒªµÄÎÊÌâÊÇ£ºÎÒÃÇÈçºÎ²ÅÄÜÈ·±£Ç¶ÈëʽϵͳÊÇ°²È«¿É¿¿µÄ£¿
C ±à³ÌÓïÑÔΪÓû§ÌṩÁËÐí¶àÇ¿´óµÄ¹¦ÄÜ£¬¼ ......

CÃæÊÔÌâ»ã×Ü

1¡¢  int a=2,b=11,c=a+b++/a++; ÔòcֵΪ¶àÉÙ£¿
¡¾¿¼µã¡¿±àÂë¹æ·¶¡£
±íÃæÉÏ¿¼²ìÄã¶ÔÔËËã·ûÓÅÏȼ¶µÄÕÆÎճ̶ȣ¬µ«Êµ¼ÊÉÏÓÅÏȼ¶ÕâЩÍæÒâºÜÄÑËÀ¼ÇÓ²±³µÃס£¿´ó¼ÒµÄÒɻ󲻾ÍÊÇÔËËã·ûµÄ½áºÏ˳Ðòô£¿ÄÇôÈçºÎÈ¥±ÜÃâÄØ£¿c=a+((b++)/(a++))²»¾ÍÐÐÁËô£¬ÆäʵÎÊÌâ±³ºó¿¼²ìµÄÊÇÄãµÄ±àÂë¹æ·¶£¬ÈçºÎдÇåÎúÒ׶®µÄ´úÂ룬ÈçºÎÔÚÒ»¸öÍÅ ......

cÖÐÊý×é´óС²»ÄÜÓñäÁ¿µÄÒ»¸ö½â¾ö°ì·¨

½ñÌìÔÚдµ½ÓÃcÀ´½âÎöpostÊý¾ÝµÄʱºòÐèÒªÓõ½Ò»¸öÊý×é±äÁ¿À´·ÅpostµÄËùÓÐÊý¾ÝµÈ×ÅÀ´½âÎö£¬²»ÏëÌ«ÀË·ÑÄÚ´æÁË¡£ÓÚÊÇÏë×ÅÏÈÉêÇëÒ»¸ö×î´óÍþ¶ûŶcontent_length´óСµÄÊý×éÔÙ˵¡£µ«ÊDz»ÔÊÐíÓñäÁ¿À´¡£±ÈÈç
int length = atoi(getenv("CONTENT_LENGTH"));
char params[length];
memset(params, '\0', length);

ÄÇôchar para ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ