Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing some directives leaving others

I use to go through C code having lot of #ifdef, #if and #endif directive which keep some portion active and some portion inactive depending on some variables are defined or not. I searched for something that can process them to generate final C code. But the preprocessing also does the same for #include and #define. But I want to keep them.

So, is there any thing to preprocess these files or project with some filtering?

like image 628
Gulshan Avatar asked Dec 14 '10 09:12

Gulshan


People also ask

What is a process directive?

What Does Preprocessor Directive Mean? Preprocessor directives are lines included in a program that begin with the character #, which make them different from a typical source code text. They are invoked by the compiler to process some programs before compilation.

What is the role of preprocessor directives?

Preprocessor directives, such as #define and #ifdef , are typically used to make source programs easy to change and easy to compile in different execution environments. Directives in the source file tell the preprocessor to take specific actions.

What are the types of Cpreprocessor directives?

There are 4 Main Types of Preprocessor Directives:Macros. File Inclusion. Conditional Compilation. Other directives.

Which set of preprocessor directives do you use?

Preprocessor directives are mostly used in defining macros, evaluating conditional statements, source file inclusion, pragma directive, line control, error detection etc. In this post, we will discuss about some more types of preprocessor directives given below: Conditional Compilation. Line control.


1 Answers

There are a series of programs that can do that:

  • unifdef - the oldest
  • sunifdef (Son of Unifdef)
  • coan (Son of sunifdef)

I've used sunifdef extensively on some very contorted code and have never found it to make a mistake. I'm ready to start using coan now, though it will still be under scrutiny for a while. Version 4.2.2 was released today, 2010-12-20.

See also: SO 525283

like image 193
Jonathan Leffler Avatar answered Oct 19 '22 04:10

Jonathan Leffler