Have compiler warn if a function is used
c, c-preprocessor, macros, warnings
Solution
While you can use #define to force errors, there is no mechanism in the C99 standard (and probably none in C11 either) to force a warning.
If you are using gcc, you can use
__attribute_deprecated__
to mark a prototype as deprecated, e.g.:
int strcmp(const char *, const char *) __attribute_deprecated__;
Problem
I have C code with lots of calls `strcmp` and `strcpy` that is causing all kinds of problems. I want to migrate this to `strncmp` and `strncpy` but I can not update all the code right now. I want to add compiler warning where ever the functions is used. The following forces the substitution `#define strcmp(x,y) strncmp16(x,y,64)` but the problem is still in the code. Is there a way to add an `#warning` so that the code still compile but will give a warning for not using the sized functions. It is a large code base and must compile in four different compilers (GCC, IAR, GHS and VC). It is our own C Library mainly used in embedded systems. Edit: I am not looking to find all occurrences. There is thousands of tools that can be used to find and replace them. I want there to be a warning so the next time somebody looks at the code they would evaluate and fix the code. Edit: Strncmp & strncpy have lots of issues and I am very aware of that. I am making an informed decision. These function is in our own C library not just the default functions from the compilers C library.