Marking library functions as deprecated

I am working on a project in C that extends an existing library (via standard includes). As the library develops a number of functions, it becomes obsolete. However, this is shown only in the documentation; the code does not put this status in any way.

I would like my project to warn me whenever I try to use one of these deprecated functions, especially since the library is under active development, so I could use something before it is deprecated and not notice when her status has changed. Is there a way I can do this under gcc without changing the library code itself? (First, it changes quite often, so the local version with gcc attributes is impractical.)

Is it possible? It looks like Visual Studio can do this with

#pragma deprecated(X,Y,...)

but i don't think gcc supports this, just

__attribute__ ((deprecated))

in the function declaration itself.

+4
source share
1 answer

Popped out of a working draft

#ifdef __GNUC__
#define DEPRECATED(X) X __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED(X) __declspec(deprecated) X
#else
#define DEPRECATED(X) X
#endif

See http://msdn.microsoft.com/en-us/library/dabb5z75.aspx and http://msdn.microsoft.com/en-us/library/044swk7y.aspx

Then

DEPRECATED(void foo(int a, int b, int c));
+4
source

Source: https://habr.com/ru/post/1540771/


All Articles