The simplest solution is to just use #warning
anyway. As your quoted cppreference page says, compilers already have been using it for years before its official standardization in C23. And as chrslg pointed out, using it on a compiler that doesn't support it will produce an error for an unsupported preprocessing directive, which should be an adequate reminder for programmers to stop using the header file.
If you want a fully C89-compatible solution, you could do:
#ifndef IGNORE_DEPRECATION
#error "This header will be removed in a future release. Use MyNewHeader.h instead."
#endif
This will treat the warning as an error, unless the program using the obsolete header (or its Makefile flags) defines the IGNORE_DEPRECATION
macro to allow the program to compile anyway.
Alternatively, you could tag all of the individual functions as deprecated. Before the deprecated
attribute was standardized in C23, compilers had custom ways of doing this:
- Microsoft Visual C++ uses
__declspec(deprecated)
, or __declspec(deprecated("custom message"))
.
- GCC uses
__attribute__((deprecated))
or (in version 8.0 and higher) __attribute__((deprecated("custom message")))
.
If you go this route, you will probably want to abstract these attributes behind macros (conditionally compiled based on _MSC_VER
and __GNUC__
versions.