路在默认情况下unifdef省略未定义preprocessor分支机构? [英] Way to omit undefined preprocessor branches by default with unifdef?

查看:137
本文介绍了路在默认情况下unifdef省略未定义preprocessor分支机构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用一个复杂的C code,它包括很多很多的编译选项。这个
使得code非常难以阅读。我想产生code的反映副本
它实际上是编译的方式。我已经得到了使用unifdefpretty良好效果
实用程序,我不知道,直到最近。不过,我不解,为什么就这么难
调用,并想​​知道如果我失去了一些东西。

I'm using a complicated C code that includes many, many compilation options. This makes the code very hard to read. I'd like to produce a copy of the code reflecting the way it's actually compiled. I've gotten pretty good results using the "unifdef" utility, which I didn't know about until recently. However, I'm puzzled why it's so hard to invoke, and am wondering if I'm missing something.

考虑这个例子:

#ifdef A
  printf("A\n");
#endif
#ifdef B
  printf("B\n");
#endif

如果你调用unifdef与unifdef-DA junk.c,您可以:

If you invoke unifdef with "unifdef -DA junk.c", you get:

  printf("A\n");
#ifdef B
  printf("B\n");
#endif

由于你没有告诉unifdef那B为不确定的,它没有把它拿出来。

Because you didn't tell unifdef that B was undefined, it didn't take it out.

我想程序的行为,这样,当我说unifdef-DA,我得到的,而不是:

I would like the utility to behave such that when I say unifdef -DA, I get instead:

  printf("A\n");

这将对应于什么样的C preprocessor实际上是这样做的:
不管分支是不确定的省略。

This would correspond to what the C preprocessor is actually doing: whatever branches are undefined are omitted.

要获得与unifdef这种行为,我似乎需要使用
unifdef -DA -UB junk.c,明确告诉它B是不确定的。
虽然也许我错过了调用它简单的方法。

To get this behavior with unifdef, I seem to need to use "unifdef -DA -UB junk.c", explicitly telling it that B is undefined. Though maybe I missed a simpler way to invoke it.

我写了一个python脚本来生成所需的-D和一长串-U
从code的Makefile的标志我使用(通常每80常规)。
和的结果是优异的。但我不知道是否有这样的脚本
实际上是必要的。

I wrote a python script to generate the long list of required -D and -U flags from the Makefile of the code I'm using (typically 80 per routine). And the results are excellent. But I'm wondering whether such a script is actually necessary.

这也有可能是其他实用程序(sunifdef?COAN?)有我的期望行为
内置了;如果是这样,请别提了。

It's also possible that another utility (sunifdef? coan?) has my desired behavior built in already; if so, please mention it.

推荐答案

COAN 工具确实需要使用 -m 标记的内容:

$ coan source -DA -m test.c 
  printf("A\n");

从手册页:

-m, --implicit
    Assume that any symbol that is not --define-ed is implicitly
    --undef-ed.

这篇关于路在默认情况下unifdef省略未定义preprocessor分支机构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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