如何编写灵活编译的程序?
如何编写灵活编译的程序?
#include "stdio.h"
void samplef(int d)
{
printf(....); // if d=1 no compile this line
printf(....); // else compile this line
}
How to write a program with flexible compile?.
#include "stdio.h"
void samplef(int d)
{
printf(....); // if d=1 no compile this line
printf(....); // else compile this line
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定你在问什么,但这听起来不可能。
编译器在编译程序时并不知道程序运行时 d 的值是什么。
我怀疑您可能误解了“编译”这个词......?
I'm not sure what you're asking, but it doesn't sound possible.
The compiler doesn't know at the time it compiles your program what the value of
d
will be when the program runs.I suspect you may have misunderstood the word "compile"...?
预处理。您正在寻找预处理。
Preprocessing. You are looking for preprocessing.
您可以使用预处理器执行类似的操作,但始终使用定义,而不是使用变量求值,因为编译器在编译时不知道该值。
You can do things like that with the preprocessor, but always is gonna be with defines, not with a variable evaluation, because the compiler doesn't know that value at compilation time.