5 ms·
What about debugging? If the code to generate the data is large and complex, how do you debug it when it only runs at compile time? Is the solution to start wit
by phkahler 9y ago
What about debugging? If the code to generate the data is large and complex, how do you debug it when it only runs at compile time? Is the solution to start with two programs like the author and then merge them? That still seems like a maintainability issue.
- nurettin 9y agoYou could use something like #ifdef NDEBUG #define MY_CONSTEXPR #else #define MY_CONSTEXPR constexpr so when you are running the debug build, everything is debuggable.
- skrebbel 9y agoThat makes the compiler not complain when your constexpr isn't a valid constexpr.
- nurettin 9y agoUntil you make release
- AlexeyBrin 9y agoA constexpr function can be used with a non-constexpr argument in which case the compiler will keep the function in the compiled code and you can use it as a normal function. In the context of the linked article, take the first example and modify it, by reading a number at runtime with std::cin and call factorial or fibonacci with this number as an argument. Something like this https://godbolt.org/g/CT5M6f https://godbolt.org/g/CT5M6f
- dawg 9y agoIn D which has CTFE support since ages, you'd debug such functions by invoking them at runtime. https://tour.dlang.org/tour/en/gems/compile-time-function-evaluation-ctfe https://tour.dlang.org/tour/en/gems/compile-time-function-ev... There are also tools to print values at compile time. A compile time debugger for the CTFE interpreter is on our extended feature list for the current interpreter rewrite, but it's less of a priority atm.
- deleted 9y ago[deleted]
- ben-schaaf 9y agoSadly it's fairly easy to write a function that fails at compile time but runs fine at runtime. For those situations there's at least `pragma(msg,`
- jcelerier 9y ago> If the code to generate the data is large and complex, how do you debug it when it only runs at compile time? that's up to the compiler actually. For instance, in debug mode visual studio skips constexpr and does everything at runtime (which sucks if you depend on stuff being constexpr).
- masklinn 9y agoconstexpr don't have to run at compile-time, they can do so. So you can use regular tests/debugging to debug your function.
- 112233 9y agowhat about cases when regular debugging is printf/assert/static_assert?
- deleted 9y ago[deleted]
- humanrebar 9y ago> ...how do you debug it when it only runs at compile time? I prefer to unit test my constexpr logic with a bunch of static assertions in a cpp file. You could put them in with the code being debugged, but having them separate keeps the header files lighter weight with no real downside assuming you have CI or something set up.