Skip to content

Instantly share code, notes, and snippets.

@bert
Last active November 8, 2019 08:03
Show Gist options
  • Select an option

  • Save bert/0659ffaf1453b82dafcbc14ef718c3ad to your computer and use it in GitHub Desktop.

Select an option

Save bert/0659ffaf1453b82dafcbc14ef718c3ad to your computer and use it in GitHub Desktop.
C inline directive
/*
Forcing inlining is useful if:
- inline is not respected by the compiler (ignored by compiler cost/benefit analyzer), and
- inlining results in a necessary performance boost
For code portability, the following preprocessor directives may be used:
*/
#ifdef _MSC_VER
#define forceinline __forceinline
#elif defined(__GNUC__)
#define forceinline inline __attribute__((__always_inline__))
#elif defined(__CLANG__)
#if __has_attribute(__always_inline__)
#define forceinline inline __attribute__((__always_inline__))
#else
#define forceinline inline
#endif
#else
#define forceinline inline
#endif
/*!
\warning gcc cannot inline functions if[3]
- they are variadic,
- use \c alloca
- use computed \c goto
- use nonlocal \c goto
- use nested functions
- use \c setjmp
- use \c __builtin_longjmp
- use \c __ builtin_return, or
- use \c __builtin_apply_args
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment