<?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>gcc | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/gcc/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>gcc | 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>
	</channel>
</rss>
