0

One can define an inline function using the inline keyword as it is shown in what follows:

inline void myFunc1() {
  cout << "FUNC1" << endl;
}

My question is, what is the difference between the aforementioned definition and the one that follows:

__attribute__((always_inline)) void myFunc2() {
  cout << "FUNC2" << endl;
}
MTMD
  • 1,162
  • 2
  • 11
  • 23
  • For starters, one is language-standard supported, the other implementation-specific. The former example will compile with any standard-conformant C++ compiler that has put `cout` and `endl` in the global namespace. The latter will work only on implementations that support `__attribute__` (ex: MSVC++ does *not*; last I checked, anyway, whilst gcc and clang do). – WhozCraig Mar 21 '19 at 00:58
  • Possible duplicate of [what “inline \_\_attribute\_\_((always\_inline))” means in the function?](https://stackoverflow.com/questions/22767523/what-inline-attribute-always-inline-means-in-the-function) See Also: [inline specifier](https://en.cppreference.com/w/cpp/language/inline) – David C. Rankin Mar 21 '19 at 01:08

0 Answers0