views:

177

answers:

4

When using sprintf, the compiler warns me that the function is deprecated.

How can I show my own compiler warning?

+6  A: 

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)

Jacob
This doesn't do exactly what Martin wants, though -- he wants the warning to be issued when the function is _used_, not when it is compiled.
Martin B
I guess my question could have be read either way (sorry for that!), but this one was what I was looking for.
Martin
+6  A: 

To mark a function as deprecated, use __declspec(deprecated), e.g.

__declspec(deprecated) void f();
Martin B
I think this is what the OP really wanted.
LiraNuna
He asks for showing his own warning, not a specific *deprecated* warning.
Georg Fritzsche
+2  A: 

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
Georg Fritzsche