作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 header ,其中一个函数声明是否定义了 DEBUG
。
我还定义了这个函数,其工作原理相同。但是我会知道 DEBUG
是否仅在参数检查后在 main()
中定义。
我已将 #include
放在 main()
中:
标题:
#ifdef DEBUG
void printStack(Stack* st);
#endif
函数定义所在的文件
#ifdef DEBUG
void printStack(Stack* st)
{
int i;
for (i = 0; i < st->size; i++)
printf(ValType_IOSPECIF " ",st->data[i]);
printf("\n");
}
#endif
main()所在的文件
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "calculating.h"
#define EXPR_LENGTH 1000
int main(int argc, char* argv[])
{
int argflag = 0;
if (argc >= 2)
argflag = !strcmp(argv[1], "-debug");
#if (argflag)
#define DEBUG
printf("! DEBUG !\n\n\n")
#endif
#include "stack.h" // there is a that function here
...
}
是吗?
最佳答案
你混淆了 C 和预处理器宏:
在编译源代码之前,以#
开头的所有内容都被预处理器替换,并且只有在运行时才会执行main
。
所以,不,你没有做对。
您不能在运行时#define
或#if
;这是编译前的事情。只需使用 C 的普通变量和 if
控制机制。
你的错误强烈表明你没有通过连贯的教程或 C 书来学习这门语言。也许您想学习新文学;我能想到的任何 C 教程都会教您如何快速完成此操作。
关于c - #include 比它出现在程序中更早,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36460705/
我安装了 fakeLoader (jquery 预加载器)但我无法在页面加载前显示它。 在 mozilla 中它几乎可以正常工作(奇怪的是......),但在 Chrome 和 Opera 中,页面首
我试图通过以下代码在触摸事件上移动 ImageView: public class ScrollableImageView extends ImageView { private Gestur
我是一名优秀的程序员,十分优秀!