当前位置:网站首页>Extern "C" overview
Extern "C" overview
2022-06-28 06:32:00 【panamera12】
1 Intention
extern "C" yes C++ Unique instructions (C Cannot use this command ), The purpose is to support C++ And C Mixed programming .
2 effect
extern “C” To tell C++ For compiler C The rule compiles the specified code ( In addition to function overloading ,extern “C” No effect C++ Other features ).
3 reason
Why use C Rule compilation C++ What about code? ?
because C and C++ The Compilation Rules are different , The main difference is that the rules for generating function symbols during compilation are inconsistent .
You can see ,MyFunction.s( The source file is .c file ) As defined in Function, and main.s( The source file is .cpp file ) What is called is _Z8Functionii, Different function names , So the function implementation cannot be found when connecting . Here we know C and C++ Get different symbols during compilation , therefore C++ Code and C Code cannot call each other .
If you want to achieve C、C++ What about mixed programming ? Make the compiled function symbols consistent ;
How consistent ? use extern "C"!
therefore ,extern “C” The purpose of this is to tell C++ compiler , Use the specified function as C Rule compilation ( Be careful , In addition to function overloading ,extern “C” No effect C++ Other features ), Then the next thing is logical .
aaa.h
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus } #endif
边栏推荐
- Rn7302 three-phase electric quantity detection (based on STM32 single chip microcomputer)
- CAD二次开发+NetTopologySuite+PGIS 引用多版本DLL问题
- EasyUI reset multi condition query
- Floating and positioning
- 手把手教你用Ucos
- easyui下拉框选中触发事件
- 链表(一)——移除链表元素
- 4. use MySQL shell to install and deploy Mgr clusters | explain Mgr in simple terms
- Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]]
- Working principle of es9023 audio decoding chip
猜你喜欢

职场IT老鸟的几点小习惯

Some habits of it veterans in the workplace

Freeswitch uses Mod_ Shot module plays mp3

How to open UMD, KMD log and dump diagrams in CAMX architecture

mac下安装多个版本php并且进行管理

Camx架构开UMD、KMD log以及dump图的方式

The custom cube UI pop-up dialog supports multiple and multiple types of input boxes

CAD二次开发+NetTopologySuite+PGIS 引用多版本DLL问题

Introduction to Qualcomm platform WiFi -- Wi Fi display software

socke.io長連接實現推送、版本控制、實時活躍用戶量統計
随机推荐
Xcode13.3.1 error reported after pod install
Shell script one click deployment (MySQL)
Scripting and programming languages
图片按日期批量导入WPS表格
[digital statistics DP] counting problem
Note that JPA uses a custom VO to receive jpql query results
AutoCAD C# 多段线自相交检测
Alert pop-up processing in Web Automation
Yolact++ Pytorch环境
Is it safe to open a stock account? How to open a stock account?
Introduction to browser tools: think sky browser, team work browser
Singleton singleton mode
助力涨点 | YOLOv5结合Alpha-IoU
Socket. Io long Connection Push, version Control, Real - Time Active user volume Statistics
[interval DP] stone consolidation
2 startup, interrupt and system call
选拔赛题目代码
Eyebeam advanced settings
Object object to list collection
YOLOv5增加小目标检测层