Thursday, July 16, 2009

use gcc to help you deprecate methods/functions in c/c++

Every so often you need to deprecate/remove/rename classes and functions in a very large project. Rather than grep'ing your way through the large source tree and trial-&-error method of compiling the project, a good way to do this would be to use the __attribute__ macro.

You assign the "deprecated" attribute to the variables, functions, methods that you plan to phase out.

GCC will cause a warning at all the places it is called.

example:
class Foo {
public: Foo() __attribute__((deprecated)) {}
};

The thing to check would be that you are not using -Wno-deprecated-declarations when building.

Since I recently switched over to using NetBeans, I can do a "Find Usages" in the entire project, but very often your project only covers the part of the code base you personally have been working on.

No comments: