469,651 Members | 1,643 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,651 developers. It's quick & easy.

create compiel time warning

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
3 1299
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
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
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.

Similar topics

6 posts views Thread by Rudolf Bargholz | last post: by
5 posts views Thread by Michael Sperlle | last post: by
9 posts views Thread by Finger.Octopus | last post: by
2 posts views Thread by copx | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.