How to get rid of ifdef in a big project c

I got an open source project encoded in C. It uses #ifdef for cross-compiling. There is a lot of ifdef in the whole source code. I want to just change it for one platform. I thought of running it through the compiler’s preprocessor (Visual C ++), but it will write the preprocessed result to a single file that I don’t need. Does anyone know a way to pre-process the project, leaving it intact (all files are untouched)? No grep, please.

change

I found a potential solution (it is surprising that you can find on the Internet these days). This is boost.wave - a C ++ preprocessor library that can do some interesting things. I don’t know how it will turn out, but I will try. However, this is not the final answer, so if you have a solution, I will be glad to hear it.

+4
source share
2 answers

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.

+4
source

Comment / delete #include directives, pre-process it, restore incoming ones.

You must make sure that all macros used by #ifdef are available, of course.

+3
source

Source: https://habr.com/ru/post/1388601/


All Articles