- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我看见了
#ifdef <token>
code;
#endif
要包含在内,但我找不到它在它包含的任何 header 中定义。是否有任何其他机制可以定义 token ?
最佳答案
首先,有些宏是由编译器隐式定义的(例如,__cplusplus
)。其中一些是标准的,一些是特定于编译器的扩展。查看您的 compiler manual查看完整列表。
此外,大多数编译器允许在命令行上定义宏。确切的机制取决于编译器,但通常采用 -D
或 /D
命令行选项的形式。例如,请参阅 gcc
manual :
-D name
Predefine name as a macro, with definition 1.
-D name=definition
The contents of definition are tokenized and processed as if they appeared during translation phase three in a `#define' directive. In particular, the definition will be truncated by embedded newline characters. If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax.
If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you will need to quote the option. With sh and csh, -D'name(args...)=definition' works.
对于 Microsoft Visual C++,请参阅 http://msdn.microsoft.com/en-us/library/hhzbb5c8(v=vs.80).aspx
一些编译器提供了方便的工具来确定特定预处理器宏的定义位置。参见,例如,How to know (in GCC) when given macro/preprocessor symbol gets declared?
关于c++ - #ifdef 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13240081/
在下面的 C 代码摘录中,SUPPORT_MULTI_DNS_SERVER 是否仅在定义 ProductName 时执行? #ifdef //do things here #ifdef SUPPO
我有一些 C++ 代码,其中有一堆 #ifdef WIN32,否则我们假设它的 IOS 代码。但是,我现在正尝试将相同的 C++ 代码用于 Android 端口。 #ifdef WIN32 是否有某种
我看过一些用于处理不同操作系统的样板头文件代码,如下所示: #ifdef __WIN32 //windows #elif __linux //linux #elif __unix
在 C++ 中,是这样的: #ifdef A && B 同: #if defined(A) && defined(B) ? 我以为不是,但我无法通过我的编译器 (VS2005) 找到差异。 最佳答案
我正在尝试理解 #ifdef 宏。下面的示例代码。 getval(int val) { if(val==0) { #ifndef PKT #define PKT #endi
我有一个包含如下命令的 Makefile: #Makefile hello: echo 'hello' echo $(TAG) ifdef TA
我正在努力让 Log4D 在 Delphi XE4 中工作,并且遇到了一些编译错误,因为它在 use 子句中找不到 Contnrs,除非我将它移到定义它的 ifdef 之外。 {$IFDEF DELP
是否可以在一个 {$IFDEF} 指令中定义多个条件? 我想要这样的语法: {$IFDEF Condition1 OR Condition2} DoSomething; {$ENDIF} {$IFDE
我经常看到这用于使模块与 GHC 和 Hugs 兼容,但谷歌并没有帮助我了解更多关于它的信息。 我可以在条件中放什么?我可以根据正在使用的“基础”版本来制作模块的一部分吗? 编辑 3/2017 :这是
在调试gen_server模块的时候,我想记录更多的细节状态。 init()-> put(?COMPLETED_COMMANDS,[]), -ifdef(DEBUG). put(?DE
在调试gen_server模块的时候,我想记录更多的细节状态。 init()-> put(?COMPLETED_COMMANDS,[]), -ifdef(DEBUG). put(?DE
我知道已经有一篇与我的类似的帖子( C++ `ifdef` with concatenation of macros values ),但该帖子相当旧,提供的解决方案对我不起作用,因为我无法设置我想要
我在编译过程中传递了一个macto: % gcc -DIDENT="abcd"app.c 在编译宏时检查宏的正确方法是什么?例如,以下内容有效,但会引发警告: #ifdef IDENT == "abc
我有一个回调函数数组。仅当定义了“SOMETHING”时才应使用一个函数。在数组中包含 #ifdef 是否正确,例如: void (*const array[])(void) = { func
是否可以在这样的 if 条件中使用 #ifdef 宏? if(Something() || SomethingElse() #ifdef __TEST__ || SomethingTest()#end
我有一个 QT 输入监听器类,它在运行的 QCoreApplication 中发出 stdin 输入信号。我想在 Windows 和 Linux 上都使用它。 我目前的方法是在 header 和 cp
我看见了 #ifdef code; #endif 要包含在内,但我找不到它在它包含的任何 header 中定义。是否有任何其他机制可以定义 token ? 最佳答案 首先,有些宏是由编译器隐式定义的
这个类是在我的项目中定义的: class B : public A { public: A& Get_a(int type); ... protected: #ifdef COMPILE_F
我正在以编程方式创建 UniversalApp。在我的应用程序中,我有 2 个常量类,并且在设备的基础上我想导入我的常量类。但它总是打开“Constants_iPad”类。甚至条件为真或假。 #ifn
我正在开发一个共享库,它有一些头文件,其中包含函数模板,例如: #ifdef somecompilerflag #define FUNCTION functionA #else #define FUN
我是一名优秀的程序员,十分优秀!