inline

C内联函数的内外链接的区别

微笑、不失礼 提交于 2019-12-06 05:43:57
C内联函数简介 inline提示编译器做可选优化,这就要求编译器能见到内联函数的定义(一般通过头文件引入编译单元),也就引入本节要讨论的焦点:内联函数外链接. 内联函数根据是否跟static修饰,分为内链接和外链接;顾名思义内链接仅在当前编译单元有效,若通过头文件引入其它编译单元,相当于一份同名拷贝,各自在不同编译单元有效,但这可能增大了二进制文件的体积(内联失败就带有多份静态函数的拷贝);外链接与之相反,它共享同一份代码. C内联函数使用 内联函数内链接 内联函数的内链接如: inline static void fn(void) {} 没有任何限制,使用简单,建议采用. 内联函数外链接 内联函数的外链接如: inline void fn(void) {} 则有诸多限制.如下: 一个非 static 的内联函数不能定义一个非 const 的函数局部 static 对象,并且不能使用文件作用域的 static 对象. static int x; inline void f(void) { static int n = 1; // 错误:非 const 的 static 对象在非 static 的 inline 函数中 int k = x; // 错误:非 static 的 inline 函数访问 static 变量 } 内联函数的外链接允许同名的外部函数,且在调用时行为是未指定的

LOJ3058. 「HNOI2019」白兔之舞

醉酒当歌 提交于 2019-12-06 05:38:15
LOJ 前置知识:任意长度NTT 普通NTT只能做 \(2^k\) 的循环卷积,尝试扩展成长度为 \(n\) 的循环卷积,保证模意义下 \(\omega_n\) 存在。 不管怎样还是要算点值。推式子: \[ \begin{align*} X_i&=\sum_{j=0}^{n-1}x_j\omega_n^{ij}\\ &=\sum_{j=0}^{n-1}x_j\omega_n^{{i+j\choose2}-{i\choose 2}-{j\choose 2}}\\ &=\omega_n^{-{i\choose 2}}\sum_{j=0}^{n-1}x_j\omega_n^{-{j\choose 2}}\times \omega_n^{{i+j\choose2}} \end{align*} \] 令 \(F_i=x_i\omega_n^{-{i\choose 2}},G_i=\omega_n^{{i\choose 2}}\) ,那么就有 \(X_i=\sum_{j=0}^{n-1} F_jG_{i+j}\) ,就可以任意模数NTT做了。 思路 发现什么性质都观察不出来,于是直接上DP。 \(dp_{i,j,x}\) 表示前 \(i\) 层,走了 \(j\) 步,走到第二维是 \(x\) 的点的方案数,有转移: \[ dp_{i,j,x}=dp_{i-1,j,x}+\sum_y dp_{i

Do c++11-compatible compilers always ignore inline hints?

≡放荡痞女 提交于 2019-12-06 05:26:07
问题 Reading an old answer on When should I write the keyword 'inline' for a function/method? that says: It is said that inline hints to the compiler that you think the function should be inlined. That may have been true in 1998, but a decade later the compiler needs no such hints. Not to mention humans are usually wrong when it comes to optimizing code, so most compilers flat out ignore the 'hint'. This answer was posted in 2009 so I want to figure it finally out: Do modern c++11-compatible

inline and good practices [duplicate]

本秂侑毒 提交于 2019-12-06 04:25:51
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: When to use inline function and when not to use it ? I have seen many source codes using different syntaxes regarding the inline directive. namespace Foo { class Bar { public: // 1 - inline on the declaration + implementation inline int sum1(int a, int b) { return a + b; } // 2 - inline on template declaration + implementation template <typename T> inline T sum2(T a, T b) { return a + b; } // 3 - Nothing special

Solid background behind text in multi-line p element

可紊 提交于 2019-12-06 02:53:05
On this slider that I'm working on, I want the description on the slide to have an orange background behind the text with a little padding on the beginning and ends of the row. I changed the p tag's display to inline and this works when it is only one line, however when the text wraps to the next line the CSS only applies the left/right padding to the left side of the first line and the right side of the last line. How can I have the padding on the left and right of each line of text without having a solid orange square the size of the full width of the container? It's the text in the slider

行列式

非 Y 不嫁゛ 提交于 2019-12-06 02:24:48
行列式 题目大意 ​ 给定一个无向联通图,求其邻接矩阵行列式。 ​ \(n\leq 3\times 10^4 , m\leq 3\times 10^5\) ,保证每个边双联通分量点数 \(\leq 50\) 题解 ​ 考虑这个邻接矩阵的行列式的意义,在不考虑行列式中的 \(-1\) 系数的情况下,就是选出若干个存在的有向环,不重不漏地覆盖每个点的方案数。 ​ 我们发现一个排列中环与环之间产生的逆序对数是可以忽略的,因此如果每个环都在一个边双内部,答案就是每个边双的答案的乘积。 ​ 考虑一个桥出现在了环中,那么一定是桥的两个端点组成了二元环。 ​ 考虑建出边双树, \(F_{x,0/1}\) 表示 \(x\) 号边双,其与边双树父亲连接的那个点有没有被环覆盖的方案数。 ​ 若 \(x\) 中一个点 \(u\) 与 \(x\) 的某个儿子 \(y\) 中的一个点 \(v\) 组成了二元环,那么我们可视为在 \(x\) 内部的邻接矩阵中, \(u\) 自己添加了一个自环,其权值自带 \(-1\) 的系数,然后求行列式即可算出 \(F_{x,1}\) 同样,我们将 \(x\) 与 \(x\) 父亲连接的点 \(w\) 在邻接矩阵的边都扣抠掉,并加上一个自环即可等价算出 \(F_{x,0}\) #include<bits/stdc++.h> #define debug(x) cerr<<#x

How do I know if a Delphi function is going to be inlined?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 01:42:57
问题 When you mark a function as inline , you hint the compiler that this function is a candidate for inlining. The compiler can still decide that it's not a good idea, and ignore it. Is there a way to see if the function gets inlined or not, without using the disassembler? Is there some compiler warning that I don't know about maybe? What are the rules for inlining that the compiler uses? Are there constructs that cause a function to never get inlined for example? 回答1: The compiler emits a hint

Inline member operators vs inline operators C++

依然范特西╮ 提交于 2019-12-06 01:24:07
If I have two structs: struct A { float x, y; inline A operator*(A b) { A out; out.x = x * b.x; out.y = y * b.y; return out; } } And an equivalent struct struct B { float x, y; } inline B operator*(B a, B b) { B out; out.x = a.x * b.x; out.y = a.y * b.y; return out; } Would you know of any reason for B's operator* to compile any differently, or run any slower or faster than A's operator* (the actual actions that go on inside the functions should be irrelevant)? What I mean is... would declaring the inline operator as a member, vs not as a member, have any generic effect on the speed of the

Will C# inline these functions?

谁说胖子不能爱 提交于 2019-12-06 01:07:58
问题 I'm writing a performance-critical application in C# and the core operation is weight calculations. The function looks like this: public void ForEachWeight(Action<int, int, float> action) { for (int lower = 0; lower < LowerLayerSize; lower++) { for (int upper = 0; upper < UpperLayerSize; upper++) { action(lower, upper, Weights[(lower * UpperLayerSize) + upper]); } } } And it gets called in dozens of places with various simple functions like: if (activationMethod == ActivationMethod.Binary) {

How to display <div> inline surrounded with text?

若如初见. 提交于 2019-12-06 01:05:18
问题 I would like to display a <div> element inline so that it is surrounded with text. My code is: <span>Here is some <div class="a"></div> text</span> Let's say, the class "a" is defined as below: .a { width:20px; height:20px; background-color:#f00; } The result should be like this: Is it doable? Thank you for any suggestions. 回答1: There's a CSS property display: inline-block; but I don't know how compatible with browsers it is (works fine in my FF) I'll do some quick testing for you. Update I