constexpr
functions are implicitly inline
, so (2) is just a more verbose version of (1). Are you worried about just release build performance, or debug performance too? Did you compare the resulting assembly? The compiler should be able to execute the function at compile-time even without constexpr
if the body is visible, so you can just make a static
function in the header (which AFAIK is the only sane way to have function definitions in headers in C), and avoid any #ifdef __cplusplus
hassle.