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

CÖÐÈçºÎµ÷ÓÃC++º¯Êý

CÖÐÈçºÎµ÷ÓÃC++º¯Êý?
 
Ç°Õó×Ó±»Îʼ°Ò»¸öÔÚCÖÐÈçºÎµ÷ÓÃC++º¯ÊýµÄÎÊÌ⣬µ±Ê±¼òµ¥»Ø´ðÊǽ«º¯ÊýÓÃextern "C"ÉùÃ÷£¬µ±±»Îʼ°ÈçºÎ½«ÀàÄÚ³ÉÔ±º¯ÊýÉùÃ÷ʱ£¬Ò»Ê±ÓïÈû£¬ºóÀ´ÍøÉϲéÁËÏ£¬ÍøÉÏÓÐÒ»·­ÒëC++Ö®¸¸µÄÎÄÕ¿ÉÒÔ×÷Ϊ½â´ð£¬ËìÄÃÀ´Markһϡ£
 
½« C++ º¯ÊýÉùÃ÷Ϊ``extern "C"''£¨ÔÚÄãµÄ C++ ´úÂëÀï×öÕâ¸öÉùÃ÷£©£¬È»ºóµ÷ÓÃËü£¨ÔÚÄãµÄ C »òÕß C++ ´úÂëÀïµ÷Óã©¡£ÀýÈ磺
// C++ code:
extern "C" void f(int);
void f(int i)
{
     // ...
}
 
È»ºó£¬Äã¿ÉÒÔÕâÑùʹÓà f()£º
/* C code: */
void f(int);
void cc(int i)
{
    f(i);
   /* ... */
    }
 
µ±È»£¬ÕâÕÐÖ»ÊÊÓÃÓڷdzÉÔ±º¯Êý¡£Èç¹ûÄãÏëÒªÔÚ C Àïµ÷ÓóÉÔ±º¯Êý£¨°üÀ¨Ð麯Êý£©£¬ÔòÐèÒªÌṩһ¸ö¼òµ¥µÄ°ü×°£¨wrapper£©¡£ÀýÈ磺
// C++ code:
class C
{
       // ...
       virtual double f(int);
};
 
extern "C" double call_C_f(C* p, int i) // wrapper function
{
       return p->f(i);
}
 
È»ºó£¬Äã¾Í¿ÉÒÔÕâÑùµ÷Óà C::f()£º
/* C code: */
double call_C_f(struct C* p, int i);
 
void ccc(struct C* p, int i)
{
       double d = call_C_f(p,i);
       /* ... */
}
 
Èç¹ûÄãÏëÔÚ C Àïµ÷ÓÃÖØÔغ¯Êý£¬Ôò±ØÐëÌṩ²»Í¬Ãû×ֵİü×°£¬ÕâÑù²ÅÄܱ» C ´úÂëµ÷Óá£ÀýÈ磺
// C++ code:
void f(int);
void f(double);
 
extern "C" void f_i(int i) { f(i); }
extern "C" void f_d(double d) { f(d); }
 
È»ºó£¬Äã¿ÉÒÔÕâÑùʹÓÃÿ¸öÖØÔØµÄ f()£º
/* C code: */
void f_i(int);
void f_d(double);
 
void cccc(int i,double d)
{
       f_i(i);
       f_d(d);
       /* ... */
}
×¢Ò⣬ÕâЩ¼¼ÇÉÒ²ÊÊÓÃÓÚÔÚ C Àïµ÷Óà C++ Àà¿â£¬¼´Ê¹Äã²»ÄÜ£¨»òÕß²»Ï룩ÐÞ¸Ä C++ Í·Îļþ¡£
 ¸Ã·­ÒëµÄÎĵµBjarne StroustrupµÄÔ­ÎÄÁ´½ÓµØÖ·ÊÇ
http://www.research.att.com/~bs/bs_faq2.html#callCpp


Ïà¹ØÎĵµ£º

C++ÖÐʹÓÃsqlite

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include ".\sqlite3_lib\sqlite3.h"
 
static int _callback_exec(void * notused,int argc, char ** argv, char ** aszColName)
{
    int i;
    for ( i=0; i<argc; i++ )
   ......

Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í

Delphi Óë C/C++ Êý¾ÝÀàÐͶÔÕÕ±í
DelphiÊý¾ÝÀàÐÍC/C++
ShorInt
8λÓзûºÅÕûÊý
char
Byte
8λÎÞ·ûºÅÕûÊý
BYTE,unsigned short
SmallInt
16λÓзûºÅÕûÊý
short
Word
16λÎÞ·ûºÅÕûÊý
unsigned short
Integer,LongInt
32λÓзûºÅÕûÊý
int,long
Cardinal,LongWord/DWORD
32λÎÞ·ûºÅÕûÊý
unsigned long
Int6 ......

JSTLÖ®c±êÇ©

Student.java£º
package com.myapp.beans;
 
public class Student {
 
       private String sno;
 
       private String sname;
 
       private Integer sage;
 
  &nbs ......

LinuxϱàÒëµ¥¸öCÎļþ

±àÒëµ¥¸öÔ´Îļþ
ΪÁ˽øÐвâÊÔ£¬Äã¿ÉÒÔ´´½¨“Hello World”³ÌÐò£º
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
printf(”Hello world!\n”);
exit(0);
}
ʹÓÃÈçÏÂÃüÁî±àÒë²¢²âÊÔÕâ¸ö´úÂ룺
# gcc -o hello hello.c
# ./hello
Hello wordl!
ÔÚÄ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ