create compiel time warning

C

Capstar

Hi NG,

I have a library of which I want to change the name of a specific method
so it is more intuitive. I plan to keep the old method in there for now
so I won't break any existing code. But I would like to get a compile
time warning when this method is called. That way a programmer using
this library sees the warning and can change his/her code.

Is this possible and if yes, how?

Thanks in advance,
Mark
 
K

Karl Heinz Buchegger

Capstar said:
Hi NG,

I have a library of which I want to change the name of a specific method
so it is more intuitive. I plan to keep the old method in there for now
so I won't break any existing code. But I would like to get a compile
time warning when this method is called. That way a programmer using
this library sees the warning and can change his/her code.

Is this possible and if yes, how?

There is no standard way.
However, most compiler offer a pragma that can do
that.
Eg. in VC++ a line

#pragma message( "Attention" )

will output the text "Attention" during compilation.

You could now

rename the function in the library
using a macro, replace any call to the function with
the sequence
#pragma message( "Warning: old function call, use XXX instead" )
call renamed function

-
Karl Heinz Buchegger
(e-mail address removed)
 
R

Rolf Magnus

Karl said:
There is no standard way.
However, most compiler offer a pragma that can do
that.
Eg. in VC++ a line

#pragma message( "Attention" )

will output the text "Attention" during compilation.

You could now

rename the function in the library
using a macro, replace any call to the function with
the sequence
#pragma message( "Warning: old function call, use XXX instead" )
call renamed function

Since the OP didn't say which compiler he's using, but seems to have posted
from a Linux system, I'll just show the g++ way, too. It defines a specific
function attribute for this that you can use like:

void my_function() __attribute__((deprecated));

Then the compiler will issue a warning on use of that function.
 
?

=?ISO-8859-1?Q?=22Nils_O=2E_Sel=E5sdal=22?=

Capstar said:
Hi NG,

I have a library of which I want to change the name of a specific method
so it is more intuitive. I plan to keep the old method in there for now
so I won't break any existing code. But I would like to get a compile
time warning when this method is called. That way a programmer using
this library sees the warning and can change his/her code.

Is this possible and if yes, how?
In the header file do;

#ifdef ENABLE_DEPRECATED
Foo YourOldStupidFroo(..);
#endif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,528
Latest member
AnaHawley8

Latest Threads

Top