当前位置:网站首页>Extern keyword
Extern keyword
2022-07-06 22:31:00 【It's Beichen not too PI acridine】
1.extern Can be placed in front of variables or functions , A function defined in a file or other variable , The variables or functions used in the following code are foreign , Not defined in this document , Prompt the compiler to look for its definition in other modules when it encounters this variable and function . It's like putting a hat on these foreign variables or functions in this document , Tell all the codes in this document , These guys are not indigenous .
C Language policy , If you omit extern, The default is external function .
extern Whether the modified variable or function is defined or declared ?
answer : It is a statement.
A.c The document defines :
int i = 10;
void fun(void)
{
//code
}
B.c Used in documents extern modification :
extern int i;
extern void fun(void);
2. as for extern“C” Usage of , It is generally believed to belong to C++ The category of , Let's not discuss it here .
extern "C" The main function of is to realize C++ Code calls other C The language code . add extern "C" after , Will instruct the compiler to press C Compiling of language , instead of C++ Of . because C++ Support function overload , Therefore, the compiler will add the function's parameter type to the compiled code when compiling the function , Not just function names ; and C Language does not support function overloading , So compile C The function of language code will not take the parameter type of function , In general, it includes function names .
This function is very useful , Because in C++ Before appearance , A lot of code is C Written language , And the bottom library is also C Written language , In order to better support the original C Code and what's written C Language library , Need to be in C++ Support as much as possible in C, and extern "C" One of the strategies .
边栏推荐
猜你喜欢
Web APIs DOM 时间对象
Balanced Multimodal Learning via On-the-fly Gradient Modulation(CVPR2022 oral)
软考高级(信息系统项目管理师)高频考点:项目质量管理
Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
Crawler obtains real estate data
LeetCode 练习——剑指 Offer 26. 树的子结构
0 basic learning C language - interrupt
Mysql database basic operations DML
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
新手程序员该不该背代码?
随机推荐
二分图判定
The SQL response is slow. What are your troubleshooting ideas?
Should novice programmers memorize code?
0 basic learning C language - interrupt
hdu 5077 NAND(暴力打表)
[Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation
MySQL数据库基本操作-DML
机试刷题1
手写ABA遇到的坑
2022-07-05 使用tpcc对stonedb进行子查询测试
UDP编程
Unity3d minigame unity webgl transform plug-in converts wechat games to use dlopen, you need to use embedded 's problem
Comparison between variable and "zero value"
第3章:类的加载过程(类的生命周期)详解
GD32F4XX串口接收中断和闲时中断配置
变量与“零值”的比较
The ceiling of MySQL tutorial. Collect it and take your time
const关键字
npm无法安装sharp
SQL Server生成自增序号