<?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>warnings | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/warnings/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, 24 Apr 2020 21:05:52 +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>warnings | 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>A useful function to know- atexit</title>
		<link>https://learncgames.com/a-useful-function-to-know-atexit/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-useful-function-to-know-atexit</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 03 May 2020 23:00:22 +0000</pubDate>
				<category><![CDATA[Source code]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[atexit]]></category>
		<category><![CDATA[warnings]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=516</guid>

					<description><![CDATA[<p>This is in C, but applies to C++ as well and is part of stdlib. Perhaps you&#8217;ve written a program and when it exits, you want it run some final code. The typical use case for this is releasing resources such as memory allocations and closing files. If you are doing networking then it might [&#8230;]</p>
The post <a href="https://learncgames.com/a-useful-function-to-know-atexit/">A useful function to know- atexit</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;:745,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/AnnaliseArt-7089643\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=4221204&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;:746,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=4221204&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 18:06:55&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-10 23:03:53&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-17 12:07:32&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-28 19:52:34&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 22:40:08&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-17 15:05:54&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-05 17:39:13&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-05 17:39:13&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_518" aria-describedby="caption-attachment-518" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-518" src="https://learncgames.com/wp-content/uploads/2020/04/street-signs-4221204_640-300x277.png" alt="Warning signs" width="300" height="277" srcset="https://learncgames.com/wp-content/uploads/2020/04/street-signs-4221204_640-300x277.png 300w, https://learncgames.com/wp-content/uploads/2020/04/street-signs-4221204_640.png 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-518" class="wp-caption-text">Image by <a href="https://pixabay.com/users/AnnaliseArt-7089643/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=4221204">Annalise Batista</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=4221204">Pixabay</a></figcaption></figure>
<p>This is in C, but applies to C++ as well and is part of <em>stdlib</em>. Perhaps you&#8217;ve written a program and when it exits, you want it run some final code. The typical use case for this is releasing resources such as memory allocations and closing files. If you are doing networking then it might also be closing network handles.</p>
<p>Then you need <em>atexit()</em>. You pass in the name of void function. When it finishes, it jumps to that function and runs it. Here&#8217;s some code to show it in use.</p>
<pre><code class="language-c" data-line="">void ExitFunction(void) {
    printf(&quot;Exited&quot;);
}    

int atv = atexit(ExitFunction);</code></pre>
<p>As good programming practice, you should check that value to make sure it&#8217;s 0. If it isn&#8217;t then your exit handler failed to register. I&#8217;m not sure what would cause that (<em>overzealous antivirus software?</em>)</p>
<p>You might notice that the ExitFunction has a (void) parameter rather than (). The two are the same but <em>atexit() </em>has been told to expect void parameters and will be disappointed should you fail to comply. Not disappointed enough to give you an error but you will incur a warning and you know how I hate to see those.</p>
<p>The reason why I hate warnings is that not all warnings are equal. This one is trivial and could be ignored, but others aren&#8217;t and really need dealing with. <strong>So I go for zero tolerance to warnings</strong>. Some compilers like gcc have a setting to tell the compiler to treat all warnings as errors.</p>The post <a href="https://learncgames.com/a-useful-function-to-know-atexit/">A useful function to know- atexit</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">516</post-id>	</item>
	</channel>
</rss>
