inline static varaible
2016-07-28 14:33
381 查看
void doSomething() { static int value ; }
You must realise that the static variable inside the function, simply put, a global variable hidden to all but the function's scope, meaning that only the function it is declared inside can reach it.
Inlining the function won't change anything:
inline void doSomething() { static int value ; }
There will be only one hidden global variable. The fact the compiler will try to inline the code won't change the fact there is only one global hidden variable.
Now, if your function is declared static:
static void doSomething() { static int value ; }
Then it is "private" for each compilation unit, meaning that every CPP file including the header where the static function is declared will have its own private copy of the function, including its own private copy of global hidden variable, thus as much variables
as there are compilation units including the header.
Adding "inline" to a "static" function with a "static" variable inside:
inline static void doSomething() { static int value ; }
has the same result than not adding this "inline" keyword, as far as the static variable inside is concerned.
相关文章推荐
- zabbix启动报错:Connection to database 'xxx' failed解决方法
- support.SerializationFailedException: Failed to deserialize payload.
- UVA 514 - Rails
- git出现Agent admitted failure to sign using the key错误
- 92.You executed the following commands in an RMAN session for your database instance that has failur
- FZU2109 Mountain Number (数位DP)
- 【HDU5745 2016 Multi-University Training Contest 2M】【二维空间维护 讨论题?排序简化!】Memento Mori 空间范围满足一定排列关系点阵数
- 【HDU5745 2016 Multi-University Training Contest 2L】【bitset做法or暴力】La Vie en rose 目标串多少子串可以被原始串做相邻交换得到
- 【HDU5744 2016 Multi-University Training Contest 2K】【水题 贪心】Keep On Movin 给定字符使得最短回文串最长
- 【HDU5743 2016 Multi-University Training Contest 2J】【dfs展开式DP 前缀和思想】Join The Future 40个数已知区间和为奇或偶输出方案
- 【HDU5742 2016 Multi-University Training Contest 2I】【简单讨论】It's All In The Mind 给定除法式尽量大
- 【HDU5741 2016 Multi-University Training Contest 2H】【线段树 扫描线】Helter Skelter 超级01串是否有恰好x个0y个1的子串
- 【HDU5740 2016 Multi-University Training Contest 2G】【二分图染色+费用流+路径输出】Glorious Brilliance 最少交换次数使得相邻点颜色
- 解决Visual Studio 2010新建工程时出现『1>LINK : fatal error LNK1123: failure during conversion to COFF: file in
- MainWindow
- 2014Shanghai Online
- lvm[12446]: Another thread is handling an event. Waiting
- 【HDU5739 2016 Multi-University Training Contest 2F】【cdq分治+并查集做法 or 点双连通做法】Fantasia 每点删除后联通块权值和的积
- 【HDU5738 2016 Multi-University Training Contest 2E】【平面点数计数 共线判定】Eureka 平面有多少个集合满足贡献
- 【HDU5735 2016 Multi-University Training Contest 2B】【暴力做法 + 折半法】Born Slippy 祖先链的最大运算权值