当前位置:网站首页>Scope of inline symbol
Scope of inline symbol
2022-07-05 05:34:00 【Raise items】
Compile time , Declare as inline The symbol of is expanded at the call , Reduce runtime overhead , At the same time, increase the size of the executable .
This article is about inline
The symbol of Scope .
Catalog
Example 1
a.cpp
#include <iostream>
inline int f()
{
return 10;
}
inline int g = 100;
void fa()
{
int a = f();
std::cout << a << std::endl;
std::cout << g << std::endl;
}
b.cpp
#include <iostream>
int f();
extern int g;
void fa();
void fb()
{
int b = f();
std::cout << b << std::endl;
std::cout << g << std::endl;
}
int main()
{
fa();
fb();
return 0;
}
Running results :
Look like extern
Scoped
Example 2
a.cpp
unchanged
#include <iostream>
inline int f()
{
return 10;
}
inline int g = 100;
void fa()
{
int a = f();
std::cout << a << std::endl;
std::cout << g << std::endl;
}
b.cpp
Define the same name inline Symbol
#include <iostream>
inline int f()
{
return 20;
}
inline int g = 200;
void fa();
void fb()
{
int b = f();
std::cout << b << std::endl;
std::cout << g << std::endl;
}
int main()
{
fa();
fb();
return 0;
}
Running results :
If it's normal extern Symbol , It should be reported redefinition Of link error , And there's no one here . In the whole project, only 1 individual f and 1 individual g, but f and g The value of is equal to Link order of . The latter link is ignored by the first link .
Example 3
a.cpp
The symbol in is declared as static
#include <iostream>
static inline int f()
{
return 10;
}
static inline int g = 100;
void fa()
{
int a = f();
std::cout << a << std::endl;
std::cout << g << std::endl;
}
b.cpp
unchanged
#include <iostream>
inline int f()
{
return 20;
}
inline int g = 200;
void fa();
void fb()
{
int b = f();
std::cout << b << std::endl;
std::cout << g << std::endl;
}
int main()
{
fa();
fb();
return 0;
}
Running results :
It is recognized in the project 2 individual f and 2 individual g, One is extern Scoped , One is static Scoped .
Conclusion
inline The symbolic scope of the modifier is extern
Of , But different from ordinary extern Symbol . In a project It is allowed to define multiple identical inline Symbol , Although it can be compiled , But after the link , Every inline Symbol Only one value will be retained .
So in a project ,inline Embellishment symbols should only
( Think of it as an ordinary extern Symbol ), Avoid quotation confusion .
边栏推荐
- Annotation and reflection
- 注解与反射
- [merge array] 88 merge two ordered arrays
- Acwing 4301. Truncated sequence
- To be continued] [UE4 notes] L4 object editing
- Fried chicken nuggets and fifa22
- Pointnet++ learning
- 全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
- Codeforces round 712 (Div. 2) d. 3-coloring (construction)
- A misunderstanding about the console window
猜你喜欢
个人开发的渗透测试工具Satania v1.2更新
CF1634E Fair Share
SAP-修改系统表数据的方法
Personal developed penetration testing tool Satania v1.2 update
F - Two Exam(AtCoder Beginner Contest 238)
YOLOv5添加注意力机制
Solution to the palindrome string (Luogu p5041 haoi2009)
Sword finger offer 05 Replace spaces
Corridor and bridge distribution (csp-s-2021-t1) popular problem solution
Yolov5 adds attention mechanism
随机推荐
Haut OJ 1321: mode problem of choice sister
YOLOv5-Shufflenetv2
Software test -- 0 sequence
Time complexity and space complexity
CF1634 F. Fibonacci Additions
[to be continued] [UE4 notes] L1 create and configure items
Csp-j-2020-excellent split multiple solutions
Acwing 4300. Two operations
Sword finger offer 53 - ii Missing numbers from 0 to n-1
卷积神经网络——卷积层
Drawing dynamic 3D circle with pure C language
Personal developed penetration testing tool Satania v1.2 update
Codeforces Round #715 (Div. 2) D. Binary Literature
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析
网络工程师考核的一些常见的问题:WLAN、BGP、交换机
Haut OJ 1218: maximum continuous sub segment sum
Haut OJ 1245: large factorial of CDs --- high precision factorial
Use of room database
[to be continued] I believe that everyone has the right to choose their own way of life - written in front of the art column
Sword finger offer 35 Replication of complex linked list