<?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>guard | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/guard/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Fri, 26 Jun 2020 13:02:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>guard | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Should you use #pragma once?</title>
		<link>https://learncgames.com/should-you-use-pragma-once/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=should-you-use-pragma-once</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Wed, 01 Jul 2020 23:00:07 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[#pragma once]]></category>
		<category><![CDATA[guard]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=914</guid>

					<description><![CDATA[<p>The traditional way of using an include guard is to put all of the header inside a #ifdef like this. #ifndef hr_time #define hr_time #include &#60;linux/time.h&#62; #include // rest of code here #endif However the modern way is to put this at the top of the header file. #pragma once And this seems supported by [&#8230;]</p>
The post <a href="https://learncgames.com/should-you-use-pragma-once/">Should you use #pragma once?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" class="alignleft size-medium wp-image-916" src="https://learncgames.com/wp-content/uploads/2020/07/pragma-300x220.png" alt="Pragma as found by google image search" width="300" height="220" srcset="https://learncgames.com/wp-content/uploads/2020/07/pragma-300x220.png 300w, https://learncgames.com/wp-content/uploads/2020/07/pragma-768x564.png 768w, https://learncgames.com/wp-content/uploads/2020/07/pragma.png 972w" sizes="(max-width: 300px) 100vw, 300px" />The traditional way of using an include guard is to put all of the header inside a #ifdef like this.</p>
<p><code class="language-c" data-line=""></code></p>
<pre><code class="language-c" data-line="">#ifndef hr_time
  #define hr_time
  #include &lt;linux/time.h&gt;
  #include 

// rest of code here
#endif</code></pre>
<p><code class="language-c" data-line=""></code></p>
<p>However the modern way is to put this at the top of the header file.</p>
<pre><code class="language-c" data-line="">#pragma once</code></pre>
<p>And this seems supported by most compilers I&#8217;ve tried. Certainly Visual Studio C/C++, gcc and clang all work.</p>
<p>In fact when you add a new file and choose <em>header</em> in Visual Studio, it put the <strong>#pragma once</strong> in automatically for you!</p>
<p>Given that those three C compilers are the main ones I use, I much prefer this pragma and use it.  But I would be interested in hearing of any C compilers that don&#8217;t  use it.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/should-you-use-pragma-once/">Should you use #pragma once?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">914</post-id>	</item>
		<item>
		<title>That Clang C compilation</title>
		<link>https://learncgames.com/that-clang-c-compilation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=that-clang-c-compilation</link>
					<comments>https://learncgames.com/that-clang-c-compilation/#comments</comments>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 10 Mar 2020 00:00:37 +0000</pubDate>
				<category><![CDATA[Clang]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[guard]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=95</guid>

					<description><![CDATA[<p>I spent about five hours trying to get the timing code to compile before I got it compiling and working. Now I&#8217;m used to the concept of include guards in C. Those are the #ifndef that you see like this: #ifndef _timeh #include &#60;linux/time.h&#62; #define _timeh 1 #endif But in the hr_time.c file these include guards [&#8230;]</p>
The post <a href="https://learncgames.com/that-clang-c-compilation/">That Clang C compilation</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:14,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250213114627\/https:\/\/github.com\/David-H-Bolton\/LearnCOnLinux&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 16:40:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 18:24:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 22:16:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 22:19:30&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 22:22:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 04:17:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 04:17:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 04:22:25&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 04:38:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 08:48:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 09:17:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 10:18:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 12:43:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 15:14:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 15:19:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-27 16:38:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-30 19:05:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 19:29:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-05 21:51:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-08 22:18:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-11 22:18:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-14 22:20:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-18 07:27:41&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-21 10:16:46&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-21 10:16:46&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p>I spent about five hours trying to get the timing code to compile before I got it compiling and working. Now I&#8217;m used to the concept of include guards in C. Those are the #ifndef that you see like this:</p>
<pre><code class="language-c" data-line="">#ifndef _timeh
  #include &lt;linux/time.h&gt;
  #define _timeh 1
#endif</code></pre>
<p>But in the <strong>hr_time.c </strong>file these include guards are on steroids. Not only did I need to include <strong>&lt;time.h&gt;</strong>, I also had to include <strong>&lt;linux/time.h&gt;</strong> but with a couple of extra #defines in there. It doesn&#8217;t seem right and wasn&#8217;t needed with the Windows version.  I&#8217;d welcome any comments on this.</p>
<pre><code class="language-c" data-line="">#ifndef _timeh
  #include &lt;linux/time.h&gt;
  #define __timespec_defined 1 
  #define __itimerspec_defined 1
  #include &lt;time.h&gt;
  #define _timeh 1
#endif</code></pre>
<p><img decoding="async" class="size-medium wp-image-98 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/sdldemo2-300x232.png" alt="The sdldemo program with timing whown in the window caption." width="300" height="232" srcset="https://learncgames.com/wp-content/uploads/2020/03/sdldemo2-300x232.png 300w, https://learncgames.com/wp-content/uploads/2020/03/sdldemo2.png 760w" sizes="(max-width: 300px) 100vw, 300px" />Without these, I&#8217;d get compile errors like <em>__timespec redefined</em> errors.</p>
<pre><code class="language-c" data-line=""></code></pre>
<p>I&#8217;ve uploaded the source files and Visual Studio Code JSON files for this in the file asteroids_ch25.zip in the new repository for the <a href="https://github.com/David-H-Bolton/LearnCOnLinux" target="_blank" rel="noopener noreferrer">Learn C on Linux Ebook</a></p>
<pre><code class="language-c" data-line=""></code></pre>
<p>So feel free to try it. The only difference between this and the version shown in an earlier post is the time (in the window caption) to draw all 100,000 rectangles,  You&#8217;ll need to install SDL2 if you want to compile and run the program.</p>The post <a href="https://learncgames.com/that-clang-c-compilation/">That Clang C compilation</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://learncgames.com/that-clang-c-compilation/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">95</post-id>	</item>
	</channel>
</rss>
