When using sprintf, the compiler warns me that the function is deprecated.
How can I show my own compiler warning?
Microsoft C++ Compiler (MSVC) This is the default compiler for most Visual Studio C++ projects and is recommended if you are targeting Windows.
The warning message for each controllable warning includes the option that controls the warning. That option can then be used with -Werror= and -Wno-error= as described above. (Printing of the option in the warning message can be disabled using the -fno-diagnostics-show-option flag.)
Compiler warnings are messages produced by a compiler regarding program code fragments to be considered by the developer, as they may contain errors. Unlike compilation errors, warnings don't interrupt the compilation process.
In Visual Studio,
#pragma message ("Warning goes here")
On a side note, if you want to suppress such warnings, find the compiler warning ID (for the deprecated warning, it's C4996
) and insert this line:
#pragma warning( disable : 4996
)
Although there is no standard #warning
directice, many compilers (including GCC, VC, Intels and Apples), support #warning message
.
#warning "this is deprecated"
Often it is better to not only bring up a warning (which people can overlook), but to let compiling fail completely, using the #error
directive (which is standard):
#if !defined(FOO) && !defined(BAR) # error "you have neither foo nor bar set up" #endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With