<?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>clang | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/clang/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>Tue, 16 Mar 2021 12:07:21 +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>clang | 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>Interesting gcc/clang extensions to C</title>
		<link>https://learncgames.com/interesting-gcc-clang-extensions-to-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=interesting-gcc-clang-extensions-to-c</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 18 Mar 2021 00:00:49 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Clang]]></category>
		<category><![CDATA[clang]]></category>
		<category><![CDATA[extensions]]></category>
		<category><![CDATA[gcc]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=2903</guid>

					<description><![CDATA[<p>Both gcc and clang support extensions to C and while i normally try and make things I write about work on Windows (i.e. Visual Studio), these are useful enough that I thought they deserve a mention. Yes I know you can run gcc/clang on Windows using Cygwin or MinGW, but for various reasons I prefer [&#8230;]</p>
The post <a href="https://learncgames.com/interesting-gcc-clang-extensions-to-c/">Interesting gcc/clang extensions to C</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignleft wp-image-2905 size-medium" src="https://learncgames.com/wp-content/uploads/2021/03/c-example-1-300x70.png" alt="C Example" width="300" height="70" srcset="https://learncgames.com/wp-content/uploads/2021/03/c-example-1-300x70.png 300w, https://learncgames.com/wp-content/uploads/2021/03/c-example-1.png 507w" sizes="(max-width: 300px) 100vw, 300px" />Both gcc and clang support extensions to C and while i normally try and make things I write about work on Windows (<em>i.e. Visual Studio</em>), these are useful enough that I thought they deserve a mention. Yes I know you can run gcc/clang on Windows using Cygwin or MinGW, but for various reasons I prefer Visual Studio.</p>
<p>You can add a constructor and destructor functions to a C program; the constructor function runs before main() and the destructor after main().</p>
<p>The syntax is not exactly clean or obvious (<em>those are double underscores before and after the word <strong>attribute</strong> like Python dunders!</em>) but I got this program to compile/run with clang 10 on Ubuntu as the screenshot shows.  Here&#8217;s a listing. I called the two functions ctor and dtor but you can use anything.</p>
<pre><code class="language-c" data-line="">#include &lt;stdio.h&gt;

__attribute__((constructor)) void ctor(void)
{
  printf(&quot;Constructor runs first\n&quot;);
}

__attribute__((destructor)) void dtor(void)
{
  printf(&quot;Destructor runs last\n&quot;);
}

int main() {
    printf(&quot;Main\n&quot;);
}</code></pre>
<p>The output  is:</p>
<pre>david@DavidPC:~/Projects/Examples$ ./ex1
Constructor runs first
Main
Destructor runs last</pre>The post <a href="https://learncgames.com/interesting-gcc-clang-extensions-to-c/">Interesting gcc/clang extensions to C</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">2903</post-id>	</item>
		<item>
		<title>Back on the Raspberry Pi</title>
		<link>https://learncgames.com/back-on-the-raspberry-pi/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=back-on-the-raspberry-pi</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 27 Nov 2020 00:00:51 +0000</pubDate>
				<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[clang]]></category>
		<category><![CDATA[compiling]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=1901</guid>

					<description><![CDATA[<p>It has been a few months since I last used it and as you&#8217;d expect, it took a little bit of time and effort to get things back to what they were. I&#8217;m pretty good about backing things up and it took about 30 minutes to burn a new SD Card, update it, install VS [&#8230;]</p>
The post <a href="https://learncgames.com/back-on-the-raspberry-pi/">Back on the Raspberry Pi</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-full wp-image-1903" src="https://learncgames.com/wp-content/uploads/2020/11/pi-asteroids.png" alt="Pi Asteroids Development" width="450" height="256" srcset="https://learncgames.com/wp-content/uploads/2020/11/pi-asteroids.png 450w, https://learncgames.com/wp-content/uploads/2020/11/pi-asteroids-300x171.png 300w" sizes="(max-width: 450px) 100vw, 450px" />It has been a few months since I last used it and as you&#8217;d expect, it took a little bit of time and effort to get things back to what they were.</p>
<p>I&#8217;m pretty good about backing things up and it took about 30 minutes to burn a new SD Card, update it, install VS Code and the C/C++ extension, then copy my asteroids version over. I use <strong>WinSCP</strong> so had to enable <strong>SSH</strong> on the PI. It&#8217;s disabled by default but just tick a checkbox on the interface tab of the Preferences-&gt;Configuration menu.</p>
<p>Even then it didn&#8217;t compile. Of course I had to reinstall the dev versions of <strong>SDL, SDL_image, SDL_mixer and SDL_ttf</strong> and the <strong>clang</strong> compiler. Still it didn&#8217;t compile. I had created a <strong>Projects</strong> folder and created an <strong>Asteroids</strong> folder underneath that. I also had the Vs Code JSON files that you need for compiling C/C++. the main one of which is <strong>tasks.json</strong>. Those were in a folder <strong>.vscode</strong> which I had backed up but I&#8217;d copied it over into the wrong location. You want it located <strong>inside</strong> your VS Code folder.</p>
<p>This makes sense. If you have say five different projects then you are going to have a different build, link stuff per project. So you&#8217;ll have a unique <strong>.vscode</strong> in each folder. When you want to switch projects, you just close the Folder in the VS Code File menu and open it in the folder for the project that you next want to work on.</p>
<p>Mind you it still wouldn&#8217;t compile. It turned out my tasks.json has <strong>clang-6</strong> in it. When I did a <strong>clang &#8211;version</strong> on it, it told me it was clang 7.0.1. So I upped it to <strong>clang-7</strong> in tasks.json and that fixed it. It all compiled and ran.</p>
<p>Once you&#8217;ve done this a time or two it becomes 2nd nature but I can understand novices frustration; there are a lot of moving parts that all have to be right before you can even write and run C code. It&#8217;s not like other programming languages are really any better though. If you have setup virtual environments in Python and installed Python modules, you&#8217;ll know what it can be like.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/back-on-the-raspberry-pi/">Back on the Raspberry Pi</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">1901</post-id>	</item>
		<item>
		<title>Fun with Raspberry Pi 4</title>
		<link>https://learncgames.com/fun-with-raspberry-pi-4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fun-with-raspberry-pi-4</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 20 Apr 2020 23:00:55 +0000</pubDate>
				<category><![CDATA[Game]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[clang]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=425</guid>

					<description><![CDATA[<p>So it turned up and I setup things up similar to the 3B+. My interest was in seeing what frame rate it can manage compared to the 27 FPS that the 3B+ managed. When I eventually got Clang, VS Code etc. installed and setup, compiled etc. it crashed just like it did on the 3B+ [&#8230;]</p>
The post <a href="https://learncgames.com/fun-with-raspberry-pi-4/">Fun with Raspberry Pi 4</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;:768,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/RonBerg-3029970\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1593406&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:769,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1593406&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:770,&quot;href&quot;:&quot;https:\/\/wiki.libsdl.org\/SDL_GetError&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20221007092534\/http:\/\/wiki.libsdl.org\/SDL_GetError&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 18:25:56&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-28 07:11:12&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-12 21:16:10&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-19 19:22:09&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-19 19:22:09&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:771,&quot;href&quot;:&quot;https:\/\/releases.llvm.org\/7.0.0\/tools\/clang\/docs\/ReleaseNotes.html&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251207150448\/https:\/\/releases.llvm.org\/7.0.0\/tools\/clang\/docs\/ReleaseNotes.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 18:25:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 07:11:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 21:16:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-22 22:47:01&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-22 22:47:01&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_428" aria-describedby="caption-attachment-428" style="width: 300px" class="wp-caption alignleft"><img decoding="async" class="size-medium wp-image-428" src="https://learncgames.com/wp-content/uploads/2020/04/ladybugs-1593406_640-300x168.jpg" alt="Bugs!" width="300" height="168" srcset="https://learncgames.com/wp-content/uploads/2020/04/ladybugs-1593406_640-300x168.jpg 300w, https://learncgames.com/wp-content/uploads/2020/04/ladybugs-1593406_640.jpg 359w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-428" class="wp-caption-text">Image by <a href="https://pixabay.com/users/RonBerg-3029970/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1593406">Ron van den Berg</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1593406">Pixabay</a></figcaption></figure>
<p>So it turned up and I setup things up similar to the 3B+. My interest was in seeing what frame rate it can manage compared to the 27 FPS that the 3B+ managed.</p>
<p>When I eventually got Clang, VS Code etc. installed and setup, compiled etc. it crashed just like it did on the 3B+ when first run. And again it failed to load the am2.msk file; I will really have to figure out what&#8217;s going on there. But also it would now not load the a1.png image. This is the one with the 24 x 280 x 280 asteroid images.</p>
<p>SDL provides a function <a title="Link goes to the LibSDL2.org Wiki page for SDL_GetError" href="https://wiki.libsdl.org/SDL_GetError" target="_blank" rel="noopener noreferrer">SDL_GetError</a> so I added that to the output when an image file fails to load. The error message that came back was <em>Texture dimensions are limited to 4096&#215;4096</em>. Now this is weird for this Pi has 4 GB of RAM (the 3B+ has 1GB) and is outputting on the same 24&#8243; monitor that the 3B+ used as well. Now it&#8217;s true that the a1.png file has dimensions of 6,720 x 64, so I can understand why that would cause grief but not why it worked on the 3B+. I suspect it has to do with RAM being allocated between the GPU and CPU so I&#8217;ll check that out.</p>
<p>I also installed Clang-6.0 to try that. On the Pi, installing clang defaults to Clang-7 (they changed the name so it no longer has a .0 on the end!). The <a title="Link to Clang-7 release notes" href="https://releases.llvm.org/7.0.0/tools/clang/docs/ReleaseNotes.html" target="_blank" rel="noopener noreferrer">release notes for Clang-7</a> suggested a possibility to do with abi incompatibility between Clang-7 and earlier versions. Bit of a longshot but I thought, that might explain the fail to load am2.msk file but no joy.</p>
<p>Well there&#8217;s nothing like juicy tender bugs to get my teeth into&#8230; the battle is on.</p>The post <a href="https://learncgames.com/fun-with-raspberry-pi-4/">Fun with Raspberry Pi 4</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">425</post-id>	</item>
		<item>
		<title>Comparing MSVC vs Clang</title>
		<link>https://learncgames.com/comparing-msvc-vs-clang/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=comparing-msvc-vs-clang</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 31 Mar 2020 23:00:12 +0000</pubDate>
				<category><![CDATA[Clang]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[clang]]></category>
		<category><![CDATA[msvc]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=275</guid>

					<description><![CDATA[<p>I originally created Asteroids for Windows using Visual Studio 2017 Community Edition. Since then I&#8217;ve started the Clang version on Ubuntu and there haven&#8217;t been too many differences but there are just a few so in this post I&#8217;ll list what I&#8217;ve found so far. Include Paths On Windows, I was able to get away [&#8230;]</p>
The post <a href="https://learncgames.com/comparing-msvc-vs-clang/">Comparing MSVC vs Clang</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="size-medium wp-image-277 alignleft" src="https://learncgames.com/wp-content/uploads/2020/03/codelisting-300x172.png" alt="Listing of some C code" width="300" height="172" srcset="https://learncgames.com/wp-content/uploads/2020/03/codelisting-300x172.png 300w, https://learncgames.com/wp-content/uploads/2020/03/codelisting.png 638w" sizes="auto, (max-width: 300px) 100vw, 300px" />I originally created Asteroids for Windows using Visual Studio 2017 Community Edition. Since then I&#8217;ve started the Clang version on Ubuntu and there haven&#8217;t been too many differences but there are just a few so in this post I&#8217;ll list what I&#8217;ve found so far.</p>
<h3>Include Paths</h3>
<p>On Windows, I was able to get away with #include &lt;SDL.h&gt; but on Linux, I&#8217;ve had to include the path so it&#8217;s #include &lt;SDL2/SDL.h&gt;. This was probably because I included the full path in the MSVC configuration.</p>
<h3>Link Failures</h3>
<p>The asteroids.c code in chapter 29 uses sin and cos for the first time and the linker was unhappy with that. So in tasks.json, I&#8217;ve explicitly had to add it into args, along with SDL2 and SDL2_image,</p>
<pre><code class="language-c" data-line="">            &quot;args&quot;: [
                &quot;-g&quot;,
                &quot;${file}&quot;,&quot;${workspaceFolder}/Asteroids/hr_time.c&quot;,
                &quot;-o&quot;,
                &quot;${fileDirname}/asteroids&quot;,                
                &quot;-lSDL2&quot;,
                &quot;-lSDL2_image&quot;,
                &quot;-lm&quot;
            ],</code></pre>
<p>That &#8220;-lm&#8221; does that for maths.</p>
<h3>Safe functions</h3>
<p>Microsoft has its own set of safe functions many with an _s and extra length parameter.</p>
<p>On Linux, there don&#8217;t seem to be so many.</p>
<p>So sprintf_s on Windows becomes snprintf.</p>
<p>fopen_s just becomes standard fopen</p>
<h3>linux/time.h</h3>
<p>As well as time.h in the includes, I needed to add linux/time.h as well.</p>The post <a href="https://learncgames.com/comparing-msvc-vs-clang/">Comparing MSVC vs Clang</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">275</post-id>	</item>
	</channel>
</rss>
