Cleaning up those CRT warnings in Visual Studio

When you need to clean up the CRT warnings about unsecure functions, like printf or sprintf, in favor for secure functions like printf_s or sprintf_s, you don’t have to scour through all of your code to clean up the warnings.

You can declare the following for Visual Studio builds and the functions are overridden with templated versions that are secure:
#ifdef _MSC_VER
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#endif

This is useful if you have a C++ cross platform file where you don’t want to create macros to have one function for the Mac and the other version for Windows.

Leave a Reply

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