How to print result of a compile-time calculation in C++?

后端 未结 5 818
刺人心
刺人心 2021-01-01 22:27

I\'ve wrote several constexpr functions and use them in static_asserts to control some resource limits. But I\'d like to not only enforce compile-time predicate but also to

5条回答
  •  春和景丽
    2021-01-01 23:23

    With most recent GCC compilers (g++, in 2020 GCC 9 at least) on at least Linux systems (and probably others) you could develop your GCC plugin adding your __builtin_compile_time_print to the existing GCC builtin functions. Or add your own #pragma or _Pragma having a similar side effect.

    I started working (with European H2020 funding from CHARIOT) on the Clips-rules-gcc project. Probably in 2 or 3 months you might be able to use it to do what you want. Please stay tuned.

    See also my obsolete GCC MELT project, which could have enabled you to do what you want with some obsolete 4.6 GCC compiler.

    Of course you could patch Clang/GCC to do similar things.

提交回复
热议问题