visual studio – How to do no-op correctly with modern C++?


I noticed before that incorrect no-op operations disrupted the code flow. I have discovered a new way now. Do you think there might be a problem?

#ifdef DEBUG
inline void print_func(std::string_view str){
    std::cout << str << std::endl;
}
#define PRINT_DEBUG print_func
#else
inline void NOOP(...) {}
#define PRINT_DEBUG NOOP

// Maybe __noop can be used but it only works in MSVC
// #define PRINT_DEBUG __noop
// https://learn.microsoft.com/en-us/cpp/intrinsics/noop?view=msvc-170

#endif

Leave a Reply

Your email address will not be published. Required fields are marked *