You may already have heard that C23 proposes a new syntax feature called attributes and that one of the standard attributes in C23 is called deprecated
. Actually, we got this whole attribute thing and also some of the standard attributes from C++, where they had been introduced in C++11 (I think). One of the uses of this particular attribute is to mark a given feature as obsolescent. For example in C23 we now have
[[deprecated]] char* asctime(const struct tm* timeptr);
[[deprecated]] char* ctime(const time_t* timer);
This simply says that user code should not use these functions anymore, and that compilers should issue a diagnostic if they do.
But this is only one of the possible uses of this new feature. First of all, it can be placed on very different kinds of features, functions, types, variables, enumeration members, structure members …
But most importantly it can be put on features that you somehow have to expose in a header, but which are really only part of the internal dealings of your code, something that users just shouldn’t touch because the feature needs careful maintenance or that simply might change in the future.
In the C23 edition of Modern C, see this post, I just modified a detailed example to use this new feature:
typedef struct circular circular;
struct circular {
size_t start [[deprecated("privat")]]; /* First element */
size_t len [[deprecated("privat")]]; /* Number of elements*/
size_t cap [[deprecated("privat")]]; /* Maximum capacity */
double* tab [[deprecated("privat")]]; /* Data array */
};
What you see here, is a structure type that can be used by application code: variables can be declared, the size is known. But none of the members of the structure can be accessed directly without being warned.
Continue reading “The deprecated attribute in C23 does much more than marking obsolescence”
You must be logged in to post a comment.