1 | #ifdef __cplusplus |
2 | extern "C" { |
3 | #endif |
4 |
5 | /*...*/ |
6 |
7 | #ifdef __cplusplus |
8 | } |
9 | #endif |
01 | #ifndef MONGOOSE_HEADER_INCLUDED |
02 | #define MONGOOSE_HEADER_INCLUDED |
03 |
04 | #ifdef __cplusplus |
05 | extern "C" { |
06 | #endif /* __cplusplus */ |
07 |
08 | /*................................. |
09 | * do something here |
10 | *................................. |
11 | */ |
12 |
13 | #ifdef __cplusplus |
14 | } |
15 | #endif /* __cplusplus */ |
16 |
17 | #endif /* MONGOOSE_HEADER_INCLUDED */ |
1 | //file1.c: |
2 | int x=1; |
3 | int b=1; |
4 | extern c; |
5 | //file2.c: |
6 | int x;// x equals to default of int type 0 |
7 | int f(); |
8 | extern double b; |
9 | extern int c; |
1 | extern "C" char* strcpy(char*,const char*); |
1 | extern char* strcpy(char*,const char*); |
1 | void print(int i); |
2 | void print(char c); |
3 | void print(float f); |
4 | void print(char* s); |
1 | _print_int |
2 | _print_char |
3 | _print_float |
4 | _pirnt_string |
1 | #ifndef C_HEADER |
2 | #define C_HEADER |
3 |
4 | extern void print(int i); |
5 |
6 | #endif C_HEADER |
1 | #i nclude <stdio.h> |
2 | #i nclude "cHeader.h" |
3 | void print(int i) |
4 | { |
5 | printf("cHeader %d\n",i); |
6 | } |
1 | extern "C"{ |
2 | #i nclude "cHeader.h" |
3 | } |
4 |
5 | int main(int argc,char** argv) |
6 | { |
7 | print(3); |
8 | return 0; |
9 | } |
1 | #ifndef CPP_HEADER |
2 | #define CPP_HEADER |
3 |
4 | extern "C" void print(int i); |
5 |
6 | #endif CPP_HEADER |
1 | #i nclude "cppHeader.h" |
2 |
3 | #i nclude <iostream> |
4 | using namespace std; |
5 | void print(int i) |
6 | { |
7 | cout<<"cppHeader "<<i<<endl; |
8 | } |
1 | extern int print(int i); |
2 | int main(int argc,char** argv) |
3 | { |
4 | print(3); |
5 | return 0; |
6 | } |
01 | typedef int (*FT) (const void* ,const void*);//style of C++ |
02 |
03 | extern "C"{ |
04 | typedef int (*CFT) (const void*,const void*);//style of C |
05 | void qsort(void* p,size_t n,size_t sz,CFT cmp);//style of C |
06 | } |
07 |
08 | void isort(void* p,size_t n,size_t sz,FT cmp);//style of C++ |
09 | void xsort(void* p,size_t n,size_t sz,CFT cmp);//style of C |
10 |
11 | //style of C |
12 | extern "C" void ysort(void* p,size_t n,size_t sz,FT cmp); |
13 |
14 | int compare(const void*,const void*);//style of C++ |
15 | extern "C" ccomp(const void*,const void*);//style of C |
16 |
17 | void f(char* v,int sz) |
18 | { |
19 | //error,as qsort is style of C |
20 | //but compare is style of C++ |
21 | qsort(v,sz,1,&compare); |
22 | qsort(v,sz,1,&ccomp);//ok |
23 |
24 | isort(v,sz,1,&compare);//ok |
25 | //error,as isort is style of C++ |
26 | //but ccomp is style of C |
27 | isort(v,sz,1,&ccopm); |
28 | } |
1 | typedef void (*HANDLER)(int); |
2 | HANDLER signal(int ,HANDLER); |
1 | void (*signal (int ,void(*)(int) ))(int) |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |