With GCC & Clang you can deprecate struct
members, (as shown below).
However I didn't see a way to do this for other compilers (MSVC for example).
While this isn't apart of the C spec and most likely relies on pragma's or custom extensions for each compiler, it would be useful to be able to support this across a wider range of compilers.
/* mytest.h */
#ifdef __GNUC__
# define ATTR_DEPRECATED __attribute__((deprecated))
#else
# define ATTR_DEPRECATED /* unsupported compiler */
#endif
struct Test {
int bar;
int foo ATTR_DEPRECATED;
};
Once a member is deprecated, the compiler should warn of its use if its accessed directly, eg:
#include "mytest.h"
static func(void)
{
Test t;
t.bar = 1;
t.foo = 0; /* <-- WARN ABOUT THIS AT COMPILE TIME */
}
Besides compilers which support GCC's __attribute__((deprecated))
(Clang for example) there aren't conventions for MSVC to deprecate struct members (With MSVC you can deprecate the identifier but that applies globally, not just to that struct).
Also no other conventions for other C compilers have been posted. So it looks like this is GCC specific.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With