【问题标题】:How to write a program with flexible compile?如何编写灵活编译的程序?
【发布时间】:2014-07-07 02:03:37
【问题描述】:

如何编写灵活编译的程序?

#include "stdio.h"
void samplef(int d)
{
   printf(....); // if d=1 no compile this line
   printf(....); // else compile this line
}

【问题讨论】:

  • 你不能根据函数参数的特定值来控制编译,它们的值是在运行时而不是编译时

标签: compilation preprocessor


【解决方案1】:

我不确定你在问什么,但这听起来不可能。

编译器在编译您的程序时并不知道程序运行时d 的值是多少。

我怀疑你可能误解了“编译”这个词...?

【讨论】:

  • 你好,我想在设计时而不是运行时编译程序
【解决方案2】:

预处理。你正在寻找preprocessing

【讨论】:

【解决方案3】:

你可以用预处理器做类似的事情,但总是用定义,而不是用变量求值,因为编译器在编译时不知道那个值。

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 2014-03-21
    相关资源
    最近更新 更多