如何在大型C项目摆脱IFDEF年代 [英] How to get rid of ifdef's in a large c project

查看:143
本文介绍了如何在大型C项目摆脱IFDEF年代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 C 得到了我的手,一个开源项目codeD。它采用的#ifdef进行交叉编译。有很多IFDEF的遍布源$ C ​​$ C。我想只是修改它的一个平台。我想通过编译器的pre-处理器(的Visual C ++)来运行它,但它会pprocessed结果写$ P $到一个单一的文件,我不需要。任何人知道的方式来pre-流程的项目,离开它的结构完整(完整的所有文件)?没有grep的,请。

I got my hands on a opensource project coded in C. It uses #ifdef's for cross-compiling. There are a lot of ifdef's all over the source code. I want just to modify it for one platform. I was thinking to run it through compiler's pre-processor (Visual C++) but it will write the preprocessed result to a single file, which I don't need. Anybody knows a way to pre-process a project leaving it's structure intact (all files intact)? No grep, please.

我发现了一个潜在的解决方案(这是惊人的,你可以找到在互联网这些天什么)。这是boost.wave - 一个C ++ preprocessor库,可以做一些有趣的东西。我不知道怎么会变成,但我会试试看。不过,这是不是最终的答案,所以如果你有一个解决方案,那么我会很高兴听到这个消息。

I found a potential solution (it's amazing what you can find on the internet these days). It's boost.wave - a C++ preprocessor library which can do some interesting stuff. I don't know how it will turn out, but I will give it a try. Still, it's not the final answer, so if you have a solution then I will be glad to hear it.

推荐答案

有两个工具,我知道的,你可以使用这个半自动做的。

There are two tools I know of that you could use to do this semi-automatically.

一是 sunifdef (儿子 unifdef )。 AFAIK,这不再被保留,但(既不是 unifdef 上,它是基于)。

One is sunifdef (son of unifdef). AFAIK, this is no longer being maintained, though (and neither is unifdef on which it is based).

COAN ,它正在积极维护,并且是一个发展 sunifdef

参见:<一href=\"http://stackoverflow.com/questions/525283/is-there-a-c-$p$p-processor-which-eliminates-ifdef-blocks-based-on-values-define\">Is有一个C pre-处理器,eliminitates基于定义的值 #IFDEF 块/未定义?。

See also: Is there a C pre-processor which eliminitates #ifdef blocks based on values defined/undefined?.

碰巧的是,我仍然使用 sunifdef 上工作的主要项目中,我消除陈旧code(例如,机器不支持自约1996年),从code基地。我与它唯一的问题在于,假如一个行云与括号内是这样的:

As it happens, I'm still using sunifdef on the main project at work where I'm eliminating archaic code (for example, machines not supported since about 1996) from the code base. The only gotcha I have with it is that if a line goes in with parentheses like this:

#if (defined(MACH_A) && defined(PROP_P)) || (defined(MACH_B) && defined(PROP_Q)) || \
    (defined(MACH_C) && defined(PROP_R))

和我们有 -UMACH_C (使机C不再支持),输出线为:

and we have -UMACH_C (so machine C is no longer supported), the output line is:

#if defined(MACH_A) && defined(PROP_P) || defined(MACH_B) && defined(PROP_Q)

从技术上讲,这很好;它是正确的。这仅仅是preferable保持额外的冗余技术括号中的前pression。

Technically, that's fine; it is correct. It is just preferable to keep the extra, technically redundant parentheses in the expression.

有一点需要注意:虽然我可以回答这些编译在基于Unix的系统上,我没有亲自检查了他们在Windows

One caveat: although I can answer for these compiling on Unix-based systems, I've not personally checked them out on Windows.

这篇关于如何在大型C项目摆脱IFDEF年代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆