GCC __attribute __ ((always_inline)) and lambdas, is this syntax correct?

I am using GCC 4.6 as part of lpcxpresso ide for the Cortex embedded processor. I have a very limited code size, especially when compiling in debug mode. Attribute use ((always_inline)) has so far established itself as a good tool for embedding trivial functions, and this saves a lot of bloating code in debug mode while maintaining readability. I expect it to be somewhat distributed and supported in the future, because http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0348c/CIAJGAIH.html is mentioned here

Now to my question: Is this the syntax for declaring a lambda always on the line?

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

It works, my question is whether it will continue to work in the future and what I can do to make it work in the future. If I ever switch to another main compiler that supports C ++ 11, I will find a similar keyword that I can replace with an attribute ((always_inline))? If I met my magical godmother, I would like the compiler directive to call all lambdas that were built as temporary with empty constructors and linked by reference, to be automatically nested even in debug mode. Any ideas?

+4
source share
1 answer

Will he continue to work in the future?

Probably, but always_inline is specific to the compiler, and since there is no standard indication of its exact behavior with a lambda, there is no guarantee that this will continue to work in the future.

What can I do to make sure it works?

It depends on the compiler, not on you. If the future version supports always_inline support with lambda, you should stick with a version that works or encodes your own preprocessor that embeds lambdas with the always_inline keyword.

If I ever switch to another main compiler that supports C ++ 11, will I find a similar keyword?

Probably, but again, there is no guarantee. The only real standard is the C ++ inline , and it does not apply to lambdas. For non-lambda, this only offers embedding and tells the compiler that the function can be defined in different compilation units.

+1
source

Source: https://habr.com/ru/post/1488687/


All Articles