#Conditional compilation for debug

10 messages · Page 1 of 1 (latest)

valid garden
#

So I have a lot of functions in my .hpp files, I want to add some print statements but I want to conditionally compile them, is there any way to do that?

cosmic creekBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

torn marlin
#

!cppref if constexpr

cosmic creekBOT
torn marlin
#
int main() {
    if constexpr(true) {
        printf("hi");
    }
}
#

Alternatively

#
int main() {
    #ifdef DEBUG
        printf("hi");
    #endif
}
valid garden
#

Thanks

silk lichen
#

There's also _DEBUG switch which is also enabled only in debug builds. For example, MSVC-specific assertions only work with this switch. I recommend checking for both:

#if defined(DEBUG) || defined(_DEBUG)
  printf("hi!");
#endif
cosmic creekBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.