Priority: Not Evaluated
Affects Version/s: 5.11.3, 5.15.1
Fix Version/s: None
Component/s: Core: Other
In this change: https://codereview.qt-project.org/c/qt/qtbase/+/305554/4, I found a bug.
When I merge the changes here into Qt5, the program cannot run. The error information is shown in the screenshot below. I think this is caused by inline functions.
The original code is like this:
If I change it to this, the program can run well:
In C++, the concept of predefined macro is realized by inline function, which is also an actual function. Inline functions have all the behaviors of normal functions. The only difference is that inline functions expand like predefined macros, so there is no cost of function calls. Therefore, we should use inline functions instead of macros normally. However, it is well known that inline functions are not always effective everywhere. There are some limitations in C + + inline compilation. The compiler may not consider inline compilation of functions in the following cases:
- There cannot be any form of circular statement
- There cannot be too many conditional statements
- The function body cannot be too large
- Function cannot be addressed
Inline is just a suggestion to the compiler. The compiler does not necessarily accept this suggestion. If you do not declare a function as an inline function, the compiler may also compile this function inline. A good compiler will inline small, simple functions.