When using sprintf, the compiler warns me that the function is deprecated.
How can I show my own compiler warning?
When using sprintf, the compiler warns me that the function is deprecated.
How can I show my own compiler warning?
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
)
To mark a function as deprecated, use __declspec(deprecated)
, e.g.
__declspec(deprecated) void f();
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