There are two tools that I know that you can use this semi-automatically.
One sunifdef (son of unifdef ). AFAIK, this is no longer supported (and not a single unifdef on which it is based).
Another coan that is actively supported, and is a development of sunifdef .
See also: Is there a C preprocessor that excludes #ifdef blocks based on specific / undefined values? .
As this happens, I still use sunifdef in the main project at work, where I remove archaic code (for example, machines that are not supported since 1996) from the code base. The only thing I have is that if the string is included in parentheses, for example:
#if (defined(MACH_A) && defined(PROP_P)) || (defined(MACH_B) && defined(PROP_Q)) || \ (defined(MACH_C) && defined(PROP_R))
and we have -UMACH_C (so C machine is no longer supported), the output line is:
#if defined(MACH_A) && defined(PROP_P) || defined(MACH_B) && defined(PROP_Q)
Technically, this is good; right. It is advisable to keep the extra, technically redundant parentheses in the expression.
One warning: although I can answer for these compilations on Unix-based systems, I have not personally tested them on Windows.
source share