如何仅对某些(#if /#endif)指令应用C预处理器? [英] How to apply a C preprocessor only to certain (#if/#endif) directives?
问题描述
我想知道是否可能,如果是的话,我可以在
C ++源文件上运行一个 C 预处理器,如cpp,只处理条件指令#if #endif等。我想要其他
指令保持完整的输出文件。
I was wondering if it is possible, and if yes how, can I run a C preprocessor, like cpp, on a C++ source file and only process the conditional directives #if #endif etc. I would like other directives to stay intact in the output file.
我对C#代码做一些分析,没有C#预处理器。我的想法是在C#文件上运行 C 预处理器,并仅处理条件。例如,#region指令将在文件中保留
,但是cpp似乎删除了#region。
I'm doing some analysis on C# code and there is no C# pre-processor. My idea is to run a C preprocessor on C# file and process only conditionals. This way for example, the #region directive, will stay in the file, but cpp appears to remove #region.
推荐答案
您可能正在寻找类似 coan 的工具:
You might be looking for a tool like coan:
Coan是一个软件工程工具,用于分析基于预处理器的C或C ++源代码配置。它的主要用途是通过消除对于指定配置多余的任何部分来简化一部分源代码。
Coan is a software engineering tool for analysing preprocessor-based configurations of C or C++ source code. Its principal use is to simplify a body of source code by eliminating any parts that are redundant with respect to a specified configuration.
设计为处理 #if
和 #ifdef
预处理器行,并相应地删除代码,但它有很多其他可能使用。
It's precisely designed to process #if
and #ifdef
preprocessor lines, and remove code accordingly, but it has a lot of other possible uses.
这篇关于如何仅对某些(#if /#endif)指令应用C预处理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!