Home > Blockchain >  Why can't inline assembly be constexpr?
Why can't inline assembly be constexpr?

Time:10-16

Is there a good reason why C doesn't allow you to constexpr inline assembly? And why are unevaluated inline assembly expressions allowed in C 20?

CodePudding user response:

The behavior of constant expressions is governed by the C standard which defines the language. The behavior of inline assembly is not. By definition, inline assembly is not C , so C can't say what happens within it.

And why are unevaluated inline assembly expressions allowed in C 20?

For the same reason many constructs are allowed in constexpr that cannot be evaluated at compile-time. constexpr functions can be called at runtime, and it'd be nice if the runtime version could invoke inline assembly.

  • Related