I think I have a serious distrust of the compiler. Do branches inside inline functions make them optimized if they have consistent results?
For an example function:
#define MODE_FROM_X_TO_Y 0 #define MODE_FROM_Y_TO_X 1 inline void swapValues(int & x, int & y, int mode) { switch(mode) { case MODE_FROM_X_TO_Y: y = x; break; case MODE_FROM_Y_TO_X: x = y; break; } }
Will be:
swapValues(n,m,MODE_FROM_X_TO_Y);
optimized as:
n = m;
First, it won’t even compile (until you add the return type).
Secondly, it swapis a very poorly chosen name (since it does not execute swapand conflicts with the name std::swap).
swap
std::swap
Third, go to http://gcc.godbolt.org/ :
Live On Godbolt
Generally speaking, the answers to these questions depend on the compiler.
, ( ) (, ), .
- - "", , .
, inline, inlining. , C/++.
inline
Source: https://habr.com/ru/post/1599671/More articles:Docker Image Hierarchy - dockerПочему в моем листе flex lexer счет увеличивается в одном случае и не увеличивается в другом? - regexIs it wrong to use object objects in all layers of a web application? - javaResize CALayer with animation in Swift - iosStartup.cs in ASP.NET 5 Class Library - c #Is the Google Dictionary API now available for the Google Custom Engine? - javaSpring Boot + Security - unable to load file (multi-page) when CSRF is enabled - javaMultiplication Order - c ++Круговые зависимости между типичными типами (CollectionType и его индекс/генератор, например) - genericsTest pattern matching type for DU - f #All Articles