最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

GCC

运维笔记admin63浏览0评论

GCC

GCC

GCC __attribute __((always_inline))和lambdas,这句法正确吗?(GCC __attribute__((always_inline)) and lambdas, is this syntax correct?)

我使用GCC 4.6作为Cortex嵌入式处理器的lpcxpresso IDE的一部分。 我的代码量非常有限,特别是在调试模式下编译时。 使用属性 ((always_inline))迄今已被证明是内联简单函数的一个好工具,这样可以在调试模式下节省大量代码,同时仍然保持可读性。 我预计它在未来会有所支持,因为它在这里提到.jsp?topic=/com.arm.doc.dui0348c/CIAJGAIH.html

现在我的问题:这是否是正确的声明Lambda总是内联的语法?

#define ALWAYS_INLINE __attribute__((always_inline))[](volatile int &i)ALWAYS_INLINE{i++;}

它确实有效,我的问题是它会在未来继续工作,我可以做些什么来确保它在未来有效。 如果我切换到另一个支持c ++ 11的主要编译器,我会找到一个类似的关键字,我可以用((always_inline))替换属性 (? 如果我要见到我的仙女教母,我希望编译器指令能够使所有构造为临时构造函数的lambda表达式具有空的构造函数,并且通过引用绑定,即使在调试模式下也是自动内联的。 有任何想法吗?

I am using GCC 4.6 as part of the lpcxpresso ide for a Cortex embedded processor. I have very limited code size, especially when compiling in debug mode. Using attribute((always_inline)) has so far proven to be a good tool to inline trivial functions and this saves a lot of code bloat in debug mode while still maintaining readability. I expect it to be somewhat mainstream and supported in the future because it is mentioned here .jsp?topic=/com.arm.doc.dui0348c/CIAJGAIH.html

Now to my question: Is this the correct Syntax for declaring a Lambda always inline?

#define ALWAYS_INLINE __attribute__((always_inline))[](volatile int &i)ALWAYS_INLINE{i++;}

It does work, my question is will it continue to work in future and what can I do to ensure it works in the future. If I ever switch to another major compiler that supports c++11 will I find a similar keyword which I can replace the attribute((always_inline)) with? If I were to meet my fairy godmother I would wish for a compiler directive which causes all lambdas which are constructed as temporaries with empty constructors and bound by reference to be automatically inlined even in debug mode. Any ideas?

最满意答案

它会继续在未来工作吗?

有可能,但always_inline是编译器特有的,因为没有标准指定lambda的确切行为,所以没有保证这将继续在未来工作。

我能做些什么来确保它有效?

这取决于编译器而不是你。 如果未来的版本使用lambda放弃对always_inline支持,那么您必须坚持一个版本,该版本可以运行或编写自己的预处理器, always_inline lambdas与always_inline like关键字一起使用。

如果我切换到另一个支持c ++ 11的主要编译器,我会找到一个类似的关键字吗?

可能但又一次,没有保证。 唯一真正的标准是C ++ inline关键字,它不适用于lambda表达式。 对于非lambda表达式,它只建议内联并告诉编译器可以在不同的编译单元中定义一个函数。

Will it continue to work in future?

Likely but, always_inline is compiler specific and since there is no standard specifying its exact behavior with lambda, there is no guaranty that this will continue to work in the future.

What can I do to ensure it works?

This depends on the compiler not you. If a future version drops support for always_inline with lambda, you have to stick with a version that works or code your own preprocessor that inlines lambdas with an always_inline-like keyword.

If I ever switch to another major compiler that supports c++11 will I find a similar keyword?

Likely but again, there is no guaranty. The only real standard is the C++ inline keyword and it is not applicable to lambdas. For non-lambda it only suggests inlining and tells the compiler that a function may be defined in different compile units.

发布评论

评论列表(0)

  1. 暂无评论