【c/c++】#pragma once 与 #ifndef 的区别解析

转载

【c/c++】#pragma once 与 #ifndef 的区别解析


原文地址:http://blog.csdn.net/hkx1n/article/details/4313303

作用:为了避免同一个文件被include多次,C/C++中有两种方式,一种是#ifndef方式,一种是#pragma once方式。

在能够支持这两种方式的编译器上,二者并没有太大的区别,但是两者仍然还是有一些细微的区别。
    

方式一:
    #ifndef __SOMEFILE_H__
    #define __SOMEFILE_H__
    ... ... // 声明、定义语句
    #endif


    方式二:

     #pragma once
    ... ... // 声明、定义语句


    #ifndef的方式受C/C++语言标准支持。它不光可以保证同一个文件不会被包含多次,也能保证内容完全相同的两个文件(或者代码片段)不会被不小心同时包含。
    当然,缺点就是如果不同头文件中的宏名不小心“撞车”,可能就会导致你看到头文件明明存在,编译器却硬说找不到声明的状况——这种情况有时非常让人抓狂。
    由于编译器每次都需要打开头文件才能判定是否有重复定义,因此在编译大型项目时,ifndef会使得编译时间相对较长,因此一些编译器逐渐开始支持#pragma once的方式。

    #pragma once一般由编译器提供保证:同一个文件不会被包含多次。注意这里所说的“同一个文件”是指物理上的一个文件,而不是指内容相同的两个文件。你无法对一个头文件中的一段代码作pragma once声明,而只能针对文件。
    其好处是,你不必再费劲想个宏名了,当然也就不会出现宏名碰撞引发的奇怪问题。大型项目的编译速度也因此提高了一些。
    对应的缺点就是如果某个头文件有多份拷贝,本方法不能保证他们不被重复包含。当然,相比宏名碰撞引发的“找不到声明”的问题,这种重复包含很容易被发现并修正。

    #pragma once方式产生于#ifndef之后,因此很多人可能甚至没有听说过。目前看来#ifndef更受到推崇。因为#ifndef受C/C++语言标准的支持,不受编译器的任何限制;而#pragma once方式却不受一些较老版本的编译器支持,一些支持了的编译器又打算去掉它,所以它的兼容性可能不够好。一般而言,当程序员听到这样的话,都会选择#ifndef方式,为了努力使得自己的代码“存活”时间更久,通常宁愿降低一些编译性能,这是程序员的个性,当然这是题外话啦。

    还看到一种用法是把两者放在一起的:

    #pragma once
    #ifndef __SOMEFILE_H__
    #define __SOMEFILE_H__
    ... ... // 声明、定义语句
    #endif

    看起来似乎是想兼有两者的优点。不过只要使用了#ifndef就会有宏名冲突的危险,也无法避免不支持#pragma once的编译器报错,所以混用两种方法似乎不能带来更多的好处,倒是会让一些不熟悉的人感到困惑。

    选择哪种方式,应该在了解两种方式的情况下,视具体情况而定。只要有一个合理的约定来避开缺点,我认为哪种方式都是可以接受的。而这个已经不是标准或者编译器的责任了,应当由程序员自己或者小范围内的开发规范来搞定。


0 个人打赏
文章最后发布于: 2016-03-03 10:03:04
        <div class="recommend-box"><div class="recommend-item-box type_blog clearfix" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/reasonyuanrobot/article/details/83858319&quot;,&quot;strategy&quot;:&quot;BlogCommendFromMachineLearnPai2&quot;,&quot;index&quot;:&quot;0&quot;}">
<div class="content" style="width: 712px;">
	<a href="https://blog.csdn.net/reasonyuanrobot/article/details/83858319" target="_blank" rel="noopener" title="关于#pragma once">
	<h4 class="text-truncate oneline" style="width: 552px;">
			关于<em>#pragma</em> on<em>c</em>e		</h4>
	<div class="info-box d-flex align-content-center">
		<p class="date-and-readNum oneline">
			<span class="date hover-show">11-08</span>
			<span class="read-num hover-hide">
				阅读数 
				2641</span>
			</p>
		</div>
	</a>
	<p class="content" style="width: 712px;">
		<a href="https://blog.csdn.net/reasonyuanrobot/article/details/83858319" target="_blank" rel="noopener" title="关于#pragma once">
			<span class="desc oneline">&nbsp;&nbsp;&nbsp;&nbsp;#pragmaonce是一个比较常用的C/C++杂注,只要在头文件的最开始加入这条杂注,就能够保证头文件只被编译一次。&nbsp;&nbsp;&nbsp;&nbsp;#pragmaonce是编译器相关的,有的编译器支持,有的编译器不...</span>
		</a>
		<span class="blog_title_box oneline ">
								<span class="type-show type-show-blog type-show-after">博文</span>
										<a target="_blank" rel="noopener" href="https://blog.csdn.net/reasonyuanrobot">来自:	<span class="blog_title"> reasonyuanrobot的博客</span></a>
											</span>
	</p>
</div>
</div>
<div class="comment-edit-box d-flex">
	<a id="commentsedit"></a>
	<div class="user-img">
		<a href="//me.csdn.net/weixin_40515248" target="_blank" rel="noopener">
			<img class="" src="https://avatar.csdn.net/9/6/A/3_weixin_40515248.jpg">
		</a>
	</div>
	<form id="commentform">
		<input type="hidden" id="comment_replyId">
		<textarea class="comment-content" name="comment_content" id="comment_content" placeholder="想对作者说点什么"></textarea>
		<div class="opt-box"> <!-- d-flex -->
			<div id="ubbtools" class="add_code">
				<a href="#insertcode" code="code" target="_self"><i class="icon iconfont icon-daima"></i></a>
			</div>
			<input type="hidden" id="comment_replyId" name="comment_replyId">
			<input type="hidden" id="article_id" name="article_id" value="50786271">
			<input type="hidden" id="comment_userId" name="comment_userId" value="">
			<input type="hidden" id="commentId" name="commentId" value="">
			<div style="display: none;" class="csdn-tracking-statistics tracking-click" data-report-click="{&quot;mod&quot;:&quot;popu_384&quot;,&quot;dest&quot;:&quot;&quot;}"><a href="#" target="_blank" class="comment_area_btn" rel="noopener">发表评论</a></div>
			<div class="dropdown" id="myDrap">
				<a class="dropdown-face d-flex align-items-center" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
				<div class="txt-selected text-truncate">添加代码片</div>
				<svg class="icon d-block" aria-hidden="true">
					<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#csdnc-triangledown"></use>
				</svg>
				</a>
				<ul class="dropdown-menu" id="commentCode" aria-labelledby="drop4">
					<li><a data-code="html">HTML/XML</a></li>
					<li><a data-code="objc">objective-c</a></li>
					<li><a data-code="ruby">Ruby</a></li>
					<li><a data-code="php">PHP</a></li>
					<li><a data-code="csharp">C</a></li>
					<li><a data-code="cpp">C++</a></li>
					<li><a data-code="javascript">JavaScript</a></li>
					<li><a data-code="python">Python</a></li>
					<li><a data-code="java">Java</a></li>
					<li><a data-code="css">CSS</a></li>
					<li><a data-code="sql">SQL</a></li>
					<li><a data-code="plain">其它</a></li>
				</ul>
			</div>  
			<div class="right-box">
				<span id="tip_comment" class="tip">还能输入<em>1000</em>个字符</span>
				<input type="button" class="btn btn-sm btn-cancel d-none" value="取消回复">
				<input type="submit" class="btn btn-sm btn-red btn-comment" value="发表评论">
			</div>
		</div>
	</form>
</div>

	<div class="comment-list-container">
	<a id="comments"></a>
	<div class="comment-list-box" style="max-height: none;"><ul class="comment-list"><li class="comment-line-box d-flex" data-commentid="8431425" data-replyname="SHU15121856">      <a target="_blank" href="https://me.csdn.net/SHU15121856"><img src="https://avatar.csdn.net/3/7/4/3_shu15121856.jpg" alt="SHU15121856" class="avatar"></a>        <div class="right-box ">          <div class="new-info-box clearfix">            <a target="_blank" href="https://me.csdn.net/SHU15121856"><span class="name ">刘知昊</span></a><span class="date" title="2018-09-09 17:45:16">1年前</span><span class="floor-num">#1楼</span><span class="new-comment">学习了</span><span class="new-opt-box"><a class="btn btn-link-blue btn-report" data-type="report">举报</a><a class="btn btn-link-blue btn-reply" data-type="reply">回复</a></span></div><div class="comment-like " data-commentid="8431425"><svg class="icon "><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#csdnc-thumbsup"></use></svg><span></span></div></div></li></ul></div>
	<div id="commentPage" class="pagination-box d-none" style="display: block;"><div id="Paging_09477601482424416" class="ui-paging-container"><ul><li class="js-page-first js-page-action ui-pager ui-pager-disabled"></li><li class="js-page-prev js-page-action ui-pager ui-pager-disabled">上一页</li><li data-page="1" class="ui-pager focus">1</li><li class="js-page-next js-page-action ui-pager ui-pager-disabled">下一页</li><li class="js-page-last js-page-action ui-pager ui-pager-disabled"></li></ul></div></div>
	
</div>

C/C++中#pragma once的使用

12-02 阅读数 1万+

C/C++中#pragmaonce的使用 博文 来自: 网络资源是无限的

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_59" data-pid="59"><script type="text/javascript">
(function() {
    var s = "_" + Math.random().toString(36).slice(2);
    document.write('<div style="" id="' + s + '"></div>');
    (window.slotbydup = window.slotbydup || []).push({
        id: "u3491668",
        container:  s
    });
})();

C语言#pragma使用方法

06-03 阅读数 5246

C语言#pragmapack使用方法 博文 来自: liuchunjie11的博客

#pragma once与#ifndef条件编译区别 - 半壶老酒 - CSDN博客

11-17

C/C++中#pragma once及#ifndef的使用 - Pin_na - CSDN博客

11-25

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_60" data-pid="60"><div class="mediav_ad"><newsfeed class="newsfeed QIHOO__WEB__SO__1570421134063_337" id="QIHOO__WEB__SO__1570421134063_337" style="display:block;margin:0;padding:0;border:none;width:900px;height:84px;overflow-y:hidden;overflow-x:hidden;position:relative;text-align:left;"><info-div id="QIHOO__WEB__SO__1570421134063_337-info" style="zoom:1"><info-div class="QIHOO__WEB__SO__1570421134063_337 singleImage clk" data-href="https://ssxd.mediav.com/s?type=2&amp;r=20&amp;mv_ref=blog.csdn.net&amp;enup=CAABcVhjKAgAAihjWHEA&amp;mvid=MTA1NzY4MTQ2MTQzMjE1MDcwMTAwMTk&amp;bid=13a3aa83bbb0f42a&amp;price=AAAAAF2auY4AAAAAAAPCk5DkH6BJd9D2DxyGfg==&amp;finfo=DAABCAABAAAAZAgAAgAAAKYEAAM/QhWnSMKlbAAIAAIAAAADCgADJKlDruRRw5gIAAQAAAC2BgAGGt0GAAoAAAgADgAAADsKAA8AAAAAABGzQwA&amp;ugi=FcTgigEVyNtrTBUCFUAVXhUAABXNm/L8AhaACBXIARaA/redxZLKBRwWxN3swYe31ImCARUAAAA&amp;uai=FeTGlAIlAhUEFozDl+/HpZ2pSRXyCCWf0b0qJQAVGhQAHBa3xte54q7wnSoVAAAA&amp;ubi=FeLnJBX0j78CFcaehBcVhrzjVxUGFRwW/oHH+hQWjMOs1tHroalJNAIWsOAQJQYV1YTSrA0VngEVACQUFuLnJAA&amp;clickid=0&amp;cpx=__OFFSET_X__&amp;cpy=__OFFSET_Y__&amp;cs=__EVENT_TIME_START__&amp;ce=__EVENT_TIME_END__&amp;adsw=__ADSPACE_W__&amp;adsh=__ADSPACE_H__&amp;ldtype=2&amp;csign2=ELYW1NkCL3Z=&amp;url=http%3A%2F%2Fbaidu.code.mytanwan.com%2Fhtmlcode%2F31331.html" data-clk="https://max-l.mediav.com/rtb?type=3&amp;ver=1&amp;v=CGQSEDEzYTNhYTgzYmJiMGY0MmEYsqOKASCisEUoAWIXMTA1NzY4MTQ2MTQzMjE1MDcwMTAwMTlwAA&amp;k=o4ULvAAAAAA=&amp;i=crTHYjgkyDZb&amp;exp=BQBECQFEAgJECgBEEQBCEABDJQBD&amp;x=__OFFSET_X__&amp;y=__OFFSET_Y__&amp;st=__EVENT_TIME_START__&amp;et=__EVENT_TIME_END__&amp;adw=__ADSPACE_W__&amp;adh=__ADSPACE_H__&amp;tc=&amp;turl=">
<info-div class="wrap">
    <info-div class="singleImage-img singleImage-img-left">
        <info-div class="img" style="background-image:url(https://s3m.mediav.com/galileo/301553-4bed552a42d15786a03698ba82bd1325.gif)"><info-div class="ads-tag"></info-div></info-div>
    </info-div>
    <info-div class="singleImage-body singleImage-body-left">
        <info-div class="singleImage-title">别再玩假传奇了!这款传奇爆率9.8,你找到充值入口算我输!</info-div>
        <info-div class="singleImage-desc">贪玩游戏 · 顶新</info-div>
    </info-div>

#pragma once与#ifndef两种防止头文件二次编译的区别 -..._CSDN博客

9-28

#pragma once和#ifndef区别 - f905699146的博客 - CSDN博客

10-4

		<div class="recommend-item-box blog-expert-recommend-box" style="display: block;">
		<div class="d-flex">
			<div class="blog-expert-recommend">
				<div class="blog-expert">
					<div class="blog-expert-flexbox" data-report-view="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/reasonyuanrobot" target="_blank"><img src="https://avatar.csdn.net/D/3/4/3_reasonyuanrobot.jpg" alt="_yuan_" title="_yuan_"></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="reasonyuanrobot" data-nick="_yuan_">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/reasonyuanrobot" target="_blank"><h5 class="oneline" title="_yuan_">_yuan_</h5></a></span>  <p></p><p class="article-num" title="115篇文章"> 115篇文章</p><p class="article-num" title="排名:千里之外"> 排名:千里之外</p><p></p></div></div></div><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/xqhrs232" target="_blank"><img src="https://avatar.csdn.net/B/4/8/3_xqhrs232.jpg" alt="xqhrs232" title="xqhrs232"></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="xqhrs232" data-nick="xqhrs232">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/xqhrs232" target="_blank"><h5 class="oneline" title="xqhrs232">xqhrs232</h5></a></span>  <p></p><p class="article-num" title="2563篇文章"> 2563篇文章</p><p class="article-num" title="排名:121"> 排名:121</p><p></p></div></div></div><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/fanyun_01" target="_blank"><img src="https://avatar.csdn.net/9/F/8/3_fanyun_01.jpg" alt="老樊Lu码" title="老樊Lu码"></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="fanyun_01" data-nick="老樊Lu码">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/fanyun_01" target="_blank"><h5 class="oneline" title="老樊Lu码">老樊Lu码</h5></a></span>  <p></p><p class="article-num" title="589篇文章"> 589篇文章</p><p class="article-num" title="排名:797"> 排名:797</p><p></p></div></div></div><div class="blog-expert-item"><div class="blog-expert-info-box"><div class="blog-expert-img-box" data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/fengbingchun" target="_blank"><img src="https://avatar.csdn.net/6/6/F/3_fengbingchun.jpg" alt="fengbingchun" title="fengbingchun"><svg class="icon" aria-hidden="true"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#csdnc-blogexpert"></use></svg></a><span data-report-click="{&quot;mod&quot;:&quot;popu_710&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><span class="blog-expert-button-follow btn-red-follow" data-name="fengbingchun" data-nick="fengbingchun">关注</span></span></div><div class="info"><span data-report-click="{&quot;mod&quot;:&quot;popu_709&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/lzm18064126848/article/details/50786271&quot;}"><a href="https://blog.csdn.net/fengbingchun" target="_blank"><h5 class="oneline" title="fengbingchun">fengbingchun</h5></a></span>  <p></p><p class="article-num" title="804篇文章"> 804篇文章</p><p class="article-num" title="排名:77"> 排名:77</p><p></p></div></div></div></div>
				</div>
			</div>
		</div>
	</div><div class="recommend-item-box baiduSearch recommend-box-ident" data-report-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_34342154/article/details/78888174&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;5&quot;}" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_34342154/article/details/78888174&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;5&quot;}" data-track-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_34342154/article/details/78888174&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:4,&quot;extend1&quot;:&quot;_&quot;}" data-track-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/qq_34342154/article/details/78888174&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:4,&quot;extend1&quot;:&quot;_&quot;}" data-flg="true">                <a href="https://blog.csdn.net/qq_34342154/article/details/78888174" target="_blank">              		<h4 class="text-truncate oneline" style="width: 633px;">...<em>#ifndef</em>,#endif,<em>#pragma</em> on<em>c</em>e ...) - 冰殇的博客 - <em>C</em>SDN博客...</h4>                  <div class="info-box d-flex align-content-center">                    <p>                      <span class="date">6-25</span>                    </p>                  </div>                </a>            	</div><div class="recommend-item-box baiduSearch recommend-box-ident" data-report-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zlhy_/article/details/8192580&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;6&quot;}" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zlhy_/article/details/8192580&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;6&quot;}" data-track-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zlhy_/article/details/8192580&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:5,&quot;extend1&quot;:&quot;_&quot;}" data-track-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zlhy_/article/details/8192580&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:5,&quot;extend1&quot;:&quot;_&quot;}" data-flg="true">                <a href="https://blog.csdn.net/zlhy_/article/details/8192580" target="_blank">              		<h4 class="text-truncate oneline" style="width: 633px;"><em>#pragma</em> on<em>c</em>e与<em>#ifndef</em>两种防止头文件二次编译的<em>区别</em> -..._<em>C</em>SDN博客</h4>                  <div class="info-box d-flex align-content-center">                    <p>                      <span class="date">10-4</span>                    </p>                  </div>                </a>            	</div>

...文件被重复包含(#pragma once 与 #ifndef区别) -..._CSDN博客

7-8

#pragma once与#ifndef区别 - holybin的专栏 - CSDN博客

11-23

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_61" data-pid="61"><div><iframe width="852" frameborder="0" height="66" scrolling="no" src="//pos.baidu.com/s?hei=66&amp;wid=852&amp;di=u3600846&amp;ltu=https%3A%2F%2Fblog.csdn.net%2Flzm18064126848%2Farticle%2Fdetails%2F50786271&amp;psi=1cd7b38bfad15850488efca9a2e2236e&amp;dc=3&amp;cec=UTF-8&amp;exps=111000,110011&amp;tlm=1570421134&amp;cfv=0&amp;cce=true&amp;dri=0&amp;pcs=1759x834&amp;col=zh-CN&amp;ps=2906x530&amp;ant=0&amp;cdo=-1&amp;tcn=1570421134&amp;dtm=HTML_POST&amp;cmi=25&amp;cja=false&amp;ari=2&amp;pis=-1x-1&amp;cpl=21&amp;ti=%E3%80%90c%2Fc%2B%2B%E3%80%91%23pragma%20once%20%E4%B8%8E%20%23ifndef%20%E7%9A%84%E5%8C%BA%E5%88%AB%E8%A7%A3%E6%9E%90&amp;tpr=1570421134336&amp;ltr=https%3A%2F%2Fblog.csdn.net%2Flzm18064126848%2Farticle%2Fdetails%2F50786271&amp;par=1600x870&amp;dis=0&amp;ccd=24&amp;dai=5&amp;prot=2&amp;drs=1&amp;psr=1600x900&amp;pss=1758x4834&amp;chi=1"></iframe></div><script type="text/javascript" src="//rabc1.iteye.com/common/web/production/79m9.js?f=aszggcwz"></script><img class="pre-img-lasy" data-src="https://kunyu.csdn.net/1.png?p=61&amp;a=622&amp;c=0&amp;k=&amp;d=1&amp;t=3&amp;u=7f2917d15a70485e820fc57c4cce5c28"></div></div><div class="recommend-item-box baiduSearch recommend-box-ident" data-report-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zzy7075/article/details/8270609&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;9&quot;}" data-report-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zzy7075/article/details/8270609&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:&quot;9&quot;}" data-track-view="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zzy7075/article/details/8270609&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:8,&quot;extend1&quot;:&quot;_&quot;}" data-track-click="{&quot;mod&quot;:&quot;popu_387&quot;,&quot;dest&quot;:&quot;https://blog.csdn.net/zzy7075/article/details/8270609&quot;,&quot;strategy&quot;:&quot;searchFromBaidu1&quot;,&quot;index&quot;:8,&quot;extend1&quot;:&quot;_&quot;}" data-flg="true">                <a href="https://blog.csdn.net/zzy7075/article/details/8270609" target="_blank">              		<h4 class="text-truncate oneline" style="width: 633px;"><em>#pragma</em> on<em>c</em>e与 <em>#ifndef</em>的<em>区别</em> - zzy7075的专栏 - <em>C</em>SDN博客</h4>                  <div class="info-box d-flex align-content-center">                    <p>                      <span class="date">10-2</span>                    </p>                  </div>                </a>            	</div>

#pragma once依然会重复包含

12-19

环境vc 描述: a.h #pragma once void f() { } b.h #pragma once #include"a.h" void f2(); b.cpp #include "b.h 论坛

#pragma comment (lib, "") 相对路径的问题

02-07

假设我的项目文件夹为c:\test 库文件夹为d:\lib,在库文件夹下有2个版本的库文件,分别存在2个文件夹下: d:\lib\ver1.0 d:\lib\ver2.0 我在项目设置里设置了“附加库 论坛

#pragma comment(lib,"winmm.lib")是什么意思

08-10

#pragma comment(lib,"winmm.lib")是什么意思 论坛

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_62" data-pid="62"><script type="text/javascript">
(function() {
    var s = "_" + Math.random().toString(36).slice(2);
    document.write('<div style="" id="' + s + '"></div>');
    (window.slotbydup = window.slotbydup || []).push({
        id: "u3600849",
        container:  s
    });
})();

#pragma language=extended的含义?

04-29

请问:程序开头部分的#pragma language=extended是什么意思? 如果没有这句,会对程序造成什么影响? 论坛

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_63" data-pid="63"><script type="text/javascript">
    (function() {
        var s = "_" + Math.random().toString(36).slice(2);
        document.write('<div style="" id="' + s + '"></div>');
        (window.slotbydup = window.slotbydup || []).push({
            id: "u4221910",
            container: s
        });
    })();

#pragma comment( lib, "Setupapi.lib")

07-30

为什么我在电脑上搜索不到Setupapi.lib,但是为什么在VS2012中链接却没有问题? 论坛

#pragma once指的是什么??

08-24

向导生成的代码有一段 #if _MSC_VER>1000 #pragma once #endif//_MSC_VER>1000 #pragma once 是什么意思 有什么作用?? 论坛

关于预处理命令#pragma SAVE #pragma REGPARMS ...... #pragma RESTORE

12-26

今天编程的时候看到如下内容,求大神帮我解释下红色部分怎么理解,或者指点我该去哪里找答案,谢谢 #pragma SAVE #pragma REGPARMS extern char _getkey (vo 论坛

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_64" data-pid="64"><script type="text/javascript">
(function() {
    var s = "_" + Math.random().toString(36).slice(2);
    document.write('<div style="" id="' + s + '"></div>');
    (window.slotbydup = window.slotbydup || []).push({
        id: "u3600856",
        container:  s
    });
})();

#pragma hdrstop究竟什么意思

08-13

最近学C++ builder; 新建一个Application; 自动出现unit1.cpp unit1.cpp 的开始部分如下: #include <vcl.h> #pragma hdrstop # 论坛

<div class="recommend-item-box recommend-recommend-box"><div id="kp_box_65" data-pid="65"><script type="text/javascript">
    (function() {
        var s = "_" + Math.random().toString(36).slice(2);
        document.write('<div style="" id="' + s + '"></div>');
        (window.slotbydup = window.slotbydup || []).push({
            id: "u4221803",
            container: s
        });
    })();

项目头文件中的宏重复定义#pragma once无效

10-31

求教各位大大,Vs 2015中VC++的控制台项目新建头文件会自动在首行加#pragma once以防止头文件重复包含,但是我的那个表达式求值的项目在生成时还是出现LNK 200重复定义,这可能是什么 论坛

            <div class="recommend-item-box type_hot_word">
                            <div class="content clearfix" style="width: 712px;">
                <div class="float-left">
                                    <span>
                    <a href="https://www.csdn.net/gather_19/MtTaAg0sMi1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c#siki第五季</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_11/MtTaAg0sNC1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c#入门推荐书</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_11/MtTaAg0sNi1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c# 解码海康数据流</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_12/MtTaAg0sNy1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c# xml的遍历循环</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_17/MtTaAg0sOC1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c# 取 查看源码没有的</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_15/MtTaAg0sOS1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c#解决高并发 委托</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_15/MtTaAg1sMC1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c#日期转化为字符串</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_14/MtTaAg1sMS1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c# 显示问号</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_1f/MtTaAg1sMi1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c# 字典对象池</a>
                </span>
                                    <span>
                    <a href="https://www.csdn.net/gather_1d/MtTaAg1sNC1kb3dubG9hZAO0O0OO0O0O.html" target="_blank">
                    c#5.0 安装程序</a>
                </span>
                                    </div>
            </div>
                            </div>
                        <div class="recommend-loading-box">
            <img src="https://csdnimg.cn/release/phoenix/images/feedLoading.gif">
        </div>
        <div class="recommend-end-box" style="display: block;">
            <p class="text-center">没有更多推荐了,<a href="https://blog.csdn.net/" class="c-blue c-blue-hover c-blue-focus">返回首页</a></p>
        </div>
    </div>
                <div class="template-box">
            <span>©️2019 CSDN</span><span class="point"></span>
        <span>皮肤主题: <a href="https://blog.csdn.net/weixin_40515248" target="_blank" style="color:#3399ea">skin3-template</a></span>
        <span> 设计师:
                                CSDN官方博客                            </span>
        </div>
                </main>
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值