By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

create compiel time warning

P: n/a
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
--
<<Remove the del for email>>
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Capstar wrote:

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
kb******@gascad.at
Jul 22 '05 #2

P: n/a
Capstar wrote:
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
Jul 22 '05 #3

P: n/a
Karl Heinz Buchegger wrote:
Capstar wrote:

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


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.

Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.