DTolm/VkFFT

Disable printing errors to `stdout`

Opened this issue · 3 comments

Currently when an error occures e. g. during kernel compilation, there are some error mesages printed to stdout. In our project, we have our own error handling and we do not want anything printed to stdout.

I would like to propose a native way to disable this behaviour e. g. by defining VKFFT_DISABLE_DEBUG_PRINTF macro or something similar before including the vkFFT.h header. It would be possible to implement it like:

#ifndef VKFFT_DISABLE_DEBUG_PRINTF
# define VKFFT_PRINTF(...) printf(__VA_ARGS__)
#else
# define VKFFT_PRINTF(...) (0)
#endif /* VKFFT_DISABLE_DEBUG_PRINTF*/

and replace every printf(...) call with VKFFT_PRINTF(...). Also it might be a better idea to output the error messages to stderr insted of stdout.

How do you feel about this change?

Thank you very much.

Best regards
David

Hello,

I will add this change, thank you. This also made me think that I can replace all sprintf calls with a macro that selects sprintf/snprintf based on user choice.

Best regards,
Dmitrii

Hello,

why do you consider still using sprintf? Is there any advantage over using snprintf? snprintf prevents the buffer overflow plus you can check if all of the characters were written to the string as "the number of characters that would be written to the string if it was long enough" is returned.

However, in each case I would suggest checking the return sprintf or snprintf - if negative, an error during formatting occured.

Best regards
David

Hello,

snprintf is not part of C89 and some older versions of MSVC do not support it. However, making printing as a macro solves both issues, so it is a good solution.

Best regards,
Dmitrii