When using sprintf, the compiler warns me that the function is deprecated.
How can I show my own compiler warning?
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
In VC if you want the warning to show up in the warning count at the end of compilation you need to use this format:
#pragma message(": warning<put what you like here>: blah blah blah")
The important sequence is: colon, space, "warning", something or nothing, colon, "your warning text"
If you want to be fancy then file and line number can be added before the 1st colon so you can double click it to jump to the code (from microsoft.com):
// pragma_directives_message1.cpp // compile with: /LD #if _M_IX86 >= 500 #pragma message("_M_IX86 >= 500") #endif #pragma message("") #pragma message( "Compiling " __FILE__ ) #pragma message( "Last modified on " __TIMESTAMP__ ) #pragma message("") // with line number #define STRING2(x) #x #define STRING(x) STRING2(x) #pragma message (__FILE__ "[" STRING(__LINE__) "]: test") #pragma message("")
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
)
I think this should work
void foo () __attribute__ ((deprecated("This function is deprecated. \nFor further information please refer to the README")));
To mark a function as deprecated, use __declspec(deprecated), e.g.
__declspec(deprecated) void f();