VkFFT icon indicating copy to clipboard operation
VkFFT copied to clipboard

Disable printing errors to `stdout`

Open davebayer opened this issue 1 year ago • 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

davebayer avatar Sep 24 '24 16:09 davebayer

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

DTolm avatar Oct 02 '24 10:10 DTolm

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

davebayer avatar Oct 05 '24 17:10 davebayer

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

DTolm avatar Oct 09 '24 17:10 DTolm