Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable printing errors to stdout #187

Open
davebayer opened this issue Sep 24, 2024 · 3 comments
Open

Disable printing errors to stdout #187

davebayer opened this issue Sep 24, 2024 · 3 comments

Comments

@davebayer
Copy link

davebayer commented Sep 24, 2024

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

@DTolm
Copy link
Owner

DTolm commented Oct 2, 2024

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

@davebayer
Copy link
Author

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

@DTolm
Copy link
Owner

DTolm commented Oct 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants