介绍 #if 和 #endif是一组同时使用的,叫做条件编译指令。 #if 与 #define、#include等指令一样是由预处理器这个强大的工具处理的, 预处理器可以在编译前处理c程序。 最常见的条件编译是防止重复包含头文件的宏,形式跟下面代码类似: #ifndef LED_H #define LED_H #endif // #ifndef LED_H 条件编译中使用的预编译指令 #define 之后的语句,相当于C语法中的else-if #else 与#if, #ifdef, #ifndef对应, 若这些条件不满足,则执行#else之后的语句,相当于C语法中的else #endif #ifdef class_2 printf("class_2\n"); #endif return 0; } 运行结果图 ? 可以明显看出,程序没有执行 #if class_1 #endif 中的程序,这是因为,在程序的开头已经定义了class_1为0,而class_2为1,程序遇见 #if #endif 只执行
想必很多人都看过“头文件中的 #ifndef/#define/#endif 防止该头文件被重复引用”。但是是否能理解“被重复引用”是什么意思? 是不是所有的头文件中都要加入#ifndef/#define/#endif 这些代码? 是不是所有的头文件中都要加入#ifndef/#define/#endif 这些代码? 答案:不是一定要加,但是不管怎样,用#ifnde xxx #define xxx#endif或者其他方式避免头文件重复包含,只有好处没有坏处。个人觉得培养一个好的编程习惯是学习编程的一个重要分支。 a.h 最后一句应该写#endif 否则不需要引入 ---------------------------------------------------------------------
Vite学习指南,基于腾讯云Webify部署项目。
char* b; b = (char*)"hello"; printf("%c\n", b[2]); system("pause"); return 0; } #endif // #if(1) int main() { printf("hello world\n"); system("pause"); return 0; } #endif // 其中,如果#if(0)里面的参数是0,那么被#if #endif包裹的代码就不会被编译器编译,也就可以在里面进行嵌入注释了。 同时,这样带来的其中一个作用是,如果我们只想在一个cpp文件中运行多段代码,而其他的不需要的不用运行,就可以将不需要运行或者编译的代码用#if(0) #endif包裹起来。
文章目录 开门见山 预处理指令 #include #define 示例一 示例二 示例三 #undef #program once program 条件编译指令 #ifdef、#ifndef、#endif #if、#elif、#else、#endif error 自我测评 开门见山 本文主要介绍c语言中条件编译相关的预编译指令,常见的预处理指令如下: #include包含一个源代码文件 #ifdef、#ifndef、#endif #ifdef用于判断某个宏是否定义,和#ifndef功能正好相反,二者仅支持判断单个宏是否已经定义 #endif用于终止#if预处理指令。 #if、#elif、#else、#endif #if可支持同时判断多个宏的存在,与常量表达式配合使用。 #endif ---- 最后,本文为我“redis6.0.6源码学习”的开路先锋,大家如有兴趣,可以点个关注一起学习呀 ?
= "" %} {% endif %} {$> enum.mlComment} {% if enum.name %}typedef {% endif --enum.name %}enum{$addIndent -- alias.typenameName %} #endif /** {$alias.name}_TYPEDEF */ {% endfor -- aliases %} {% endif -- aliases -- us.type == "union/struct" %} #endif /** {$us.name}_DEFINED */ {% endif -- ! -- consts %} #endif // ERPC_TYPE_DEFINITIONS {% endif -- commonTypesFile %} {% if not genCommonTypesFile {% endif -- genCommonTypesFile %} #endif // {$commonGuardMacro} 以上模板文件在码云仓库的位置 https://gitee.com/l0km
--[endif]--> action-servlet.xml 配置文件 <? --[endif]--> <beans> <! --[endif]--> </beans> <! --[endif]-->
[endif]--> <! [endif]--> <! [endif]--> <! [endif]--> 我是IE10或非IE浏览器!
_IA64_ */ #endif #ifndef _MAC #if defined(_68K_) || defined(_MPPC_) #define _MAC #endif #endif #if <winver.h> #endif #if ! INC_OLE1 */ #endif /* !MAC */ #include <commdlg.h> #endif /* ! #include <imm.h> #endif #endif /* WINVER >= 0x0400 */ #endif #ifndef RC_INVOKED #if ( _MSC_VER It's an unneeded warning anyway. */ #endif #endif #endif /* RC_INVOKED */ #endif /* RC_INVOKED */ #
先前写的一个工具(Qml宏预处理工具)顺便就总结一下if/elif/else/endif之间的嵌套关系,并整理成表。 从左到右顺序,与之上一个宏定义对比。除去2个无效项,共有14个有效项。 if elif else endif if 创建子层 同层逻辑 同层逻辑 同层逻辑 elif 创建子层 同层逻辑 同层逻辑 同层逻辑 else 创建子层 无效 无效 同层逻辑 endif 创建分组层 上一层逻辑 #if /* elif - > if 创建子层 */ #elif #elif #endif #else #if /* else - > if 创建子层 */ #else #endif #endif #if /* endif -> if 创建分组层 */ #if #if #if #endif #elif /* endif -> elif 上一层逻辑 */ #else #endif #else /* endif -> else 上一层逻辑 */ #endif #endif /* endif -> endif 上一层逻辑 */
'-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg1 '\diff"' endif else let cmd = $VIMRUNTIME . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg1 '\diff"' endif else let cmd = $VIMRUNTIME .
[endif]--> if !IE :非IE浏览器可见 代码如下: <![if ! [endif]--> 2、用在页面内,可用于提示浏览器升级: 如下图: ?
endif. endif. if not itab-field is initial. exit. endif. enddo. endif. endif. endif.
up to date" 192 endif 193 endif 194 setlocal makeprg=make 195 endfunc 196 /%<" 221 endif 222 endif 223 redraw! '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 '\diff"' endif else let cmd = $VIMRUNTIME . '\diff' endif silent execute '!'
endfor$ $endif$ $if(listings)$ \usepackage{listings} $endif$ $if(lhs)$ \lstnewenvironment{code}{\lstset $ $endif$ $if(verbatim-in-note)$ \usepackage{fancyvrb} \VerbatimFootnotes $endif$ $if(tables)$ \usepackage \title{\bfseries \huge $title$$if(subtitle)$\\\vspace{0.5cm}{\Large $subtitle$}$endif$} $endif$ $if( $endif$ $if(lof)$ \listoffigures $endif$ $body$ $if(natbib)$ $if(bibliography)$ $if(biblio-title)$ $ $endif$ \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$} $endif$ $endif$ $if(biblatex
[endif] wasSignalled =false; [if !supportLists]15. [endif] } [if !supportLists]16. [endif] } [if ! [endif]ClassReordering { [if !supportLists]2. [endif] [if !supportLists]3. [endif] int x = 0, y = 0; [if !supportLists]4. [endif] [if !supportLists]5. [endif] y =2; [if !supportLists]8. [endif] } [if !supportLists]9. [endif] [if !supportLists]10. [endif] int r2 = x; [if !supportLists]13. [endif] } [if !supportLists]14.
[endif]--> <! [endif]--> <! [endif]--> 项目 范例 说明 ! [endif]-->
[endif]--> <! [endif]--> <! [endif]--> <! [endif]––> <!––[if IE 5.0]> 版本 5.0 <![endif]––> <! [endif]––> <!––[if IE 6]> 版本 6 <![endif]––> <!
ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. ENDWHILE. ENDIF. ENDIF. ENDIF.
btn-warning btn-sm"> {% if post.can_comment %}Disable{% else %}Enable{% endif %} Comment </button> </form> {% endif %} > <a href="{% if comment.site %}{{ comment.site }}{% else %}#{% <em>endif</em> (pagination, fragment='#comments') }} {% <em>endif</em> %} {% if request.args.get('reply') %} </h5></div> {% <em>endif</em> %} </div>
校园优惠套餐升级,云服务器1核2G10元/月起购
扫码关注云+社区
领取腾讯云代金券