Domanda

I'm working on a project in C which extends an existing library (via standard includes). As the library develops a number of functions become deprecated. However this is shown only in the documentation; the code does not mark this status in any way.

I'd like to have my project warn me whenever I attempt to use one of these deprecated functions, especially since the library is under active development so I might have used something before deprecation and not noticed when its status changed. Is there any way I can do this under gcc, short of modifying the library code itself? (For one thing, it changes often enough that keeping a local version with gcc attributes is impractical.)

Is this possible? It seems like Visual Studio could do this with its

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

syntax, but I don't think gcc supports this, just

__attribute__ ((deprecated))

on a function declaration itself.

È stato utile?

Soluzione

Pulled from a working project

#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));
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top