<?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>assert | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/assert/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, 03 Jul 2020 09:44: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>assert | 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>Do you use assert in your code?</title>
		<link>https://learncgames.com/do-you-use-assert-in-your-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=do-you-use-assert-in-your-code</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Tue, 07 Jul 2020 23:00:40 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Source code]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[assert]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=951</guid>

					<description><![CDATA[<p>It&#8217;s a macro that checks an expression, and if that expression isn&#8217;t true (.e. non-zero) it outputs a message and halts the program. Here&#8217;s an example. #include #include int main() { int x = 0; assert(x != 0); printf(&#34;It is the end&#34;); } Because x is 0, it triggers the assert and the program never [&#8230;]</p>
The post <a href="https://learncgames.com/do-you-use-assert-in-your-code/">Do you use assert in your code?</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 size-full wp-image-952" src="https://learncgames.com/wp-content/uploads/2020/07/assert.png" alt="assert" width="262" height="76" />It&#8217;s a macro that checks an expression, and if that expression isn&#8217;t true (.e. non-zero) it outputs a message and halts the program.</p>
<p>Here&#8217;s an example.</p>
<pre><code class="language-c" data-line="">#include 
#include 

int main() {
	int x = 0;
	assert(x != 0);
	printf(&quot;It is the end&quot;);
}</code></pre>
<p>Because x is 0, it triggers the assert and the program never reaches the printf statement. It&#8217;s a bit of a crude tool. In other programming languages like C++ or Delphi it raises an exception which can be handles but C of course does not have exceptions.</p>
<p>My own preference is to check the value for example making sure a pointer is not null and nthen displaying an error but other programmers prefer to use assert and have it kill the program if things go wrong.</p>The post <a href="https://learncgames.com/do-you-use-assert-in-your-code/">Do you use assert in your code?</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">951</post-id>	</item>
	</channel>
</rss>
