<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Library of Graphics &#187; compile</title>
	<atom:link href="http://libg.org/tag/compile/feed/" rel="self" type="application/rss+xml" />
	<link>http://libg.org</link>
	<description>Computer Graphics: Fundamental and Practice</description>
	<lastBuildDate>Mon, 23 Mar 2009 03:12:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Include Guard: #pragma once vs. #ifndef #define #endif</title>
		<link>http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/</link>
		<comments>http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 04:08:38 +0000</pubDate>
		<dc:creator>Mason</dc:creator>
				<category><![CDATA[General C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[compile]]></category>

		<guid isPermaLink="false">http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/</guid>
		<description><![CDATA[In the C and C++ programming languages, an include guard, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the #include directive. The addition of include guards to a header file is one way to achieve this. pragma once is a non-standard but widely supported preprocessor directive designed to ...]]></description>
			<content:encoded><![CDATA[<p>In the C and C++ programming languages, an <strong>include guard</strong>, sometimes called a macro guard, is a particular construct used to avoid the problem of double inclusion when dealing with the #include directive. The addition of include guards to a header file is one way to achieve this. <strong>pragma once </strong>is a non-standard but widely supported preprocessor directive designed to cause the current source file to be included only once in a single compilation. Both approaches specify that the file will be included only once by the compiler when compiling a source code file.</p>
<p>The table below compared the details of <strong>pragma once</strong> and <strong>#ifndef #define #endif </strong>approach:</p>
<table border="1" cellspacing="0" cellpadding="2" width="598">
<tbody>
<tr>
<td width="157" valign="top"></td>
<td width="202" valign="top"><strong>pragma once</strong></td>
<td width="236" valign="top"><strong>#ifndef #define #endif</strong></td>
</tr>
<tr>
<td width="157" valign="top"><strong>Sample code</strong></td>
<td width="202" valign="top">
<pre name="code" class="cpp:nocontrols">
// header file
#pragma once
class foo { };
</pre>
</td>
<td width="236" valign="top">
<pre name="code" class="cpp:nocontrols">
// header file
#ifndef FOO_HEADER
#define FOO_HEADER
class foo { };
#endif // FOO_HEADER
</pre>
</td>
</tr>
<tr>
<td width="157" valign="top"><strong>C++ Standard</strong></td>
<td width="202" valign="top"><strong>No</strong></p>
<p>But both GCC and Microsoft Visual C++ support it.</td>
<td width="236" valign="top"><strong>Yes</strong></td>
</tr>
<tr>
<td width="157" valign="top"><strong>Compiling Performance</strong></td>
<td width="202" valign="top"><strong>Better</strong></p>
<p><strong></strong>This can reduce build times as the compiler will not open and read the file after the first #include of the module.</td>
<td width="236" valign="top">It will still have to open the file multiple times, and discard the guard part when compiler find the macro guard. In a large project this could cause increased compile times.</p>
<p>But you can also optimize the compiling performance of #ifdef #define #endif approach by <a href="http://www.bobarcher.org/software/include/index.html" target="_blank">this way</a>.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://libg.org/2008/09/06/include-guard-pragma-once-vs-ifdef-define-endif/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
