c++对c的拓展_extern "C" 浅谈

extern "C" :c++编译器编译c函数时需要声明extern “C”

main.cpp                                   test.h                                test.c

# include <iostream>                 #pragma once                 int test(int a,int b){

# include "test.h"                        #if __cpulspuls                 return a*b;

using namespace std;               exturn "C"{

int main(){                                  #endif

int a=1;                                       int test(int a,int b);

int b=2;                                       #if __cplusplus

cout << test(a,b)<<endl;             }

return 0;                                       #endif

}                                                 

 

posted @ 2022-04-06 12:04  spking  阅读(58)  评论(0)    收藏  举报