<?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>Last Ray of Hope &#187; stdlib</title>
	<atom:link href="http://www.lastrayofhope.com/tag/stdlib/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lastrayofhope.com</link>
	<description>Home of Kaluriel Hargrove</description>
	<lastBuildDate>Thu, 02 Feb 2012 00:21:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>SprintfCat</title>
		<link>http://www.lastrayofhope.com/2011/11/02/sprintfcat/</link>
		<comments>http://www.lastrayofhope.com/2011/11/02/sprintfcat/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 15:17:23 +0000</pubDate>
		<dc:creator>Kaluriel</dc:creator>
				<category><![CDATA[Athena]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[safe]]></category>
		<category><![CDATA[sprintf]]></category>
		<category><![CDATA[stdlib]]></category>
		<category><![CDATA[strlen]]></category>
		<category><![CDATA[vsprintf]]></category>

		<guid isPermaLink="false">http://www.lastrayofhope.com/?p=3975</guid>
		<description><![CDATA[On the train to Cardiff yesterday, I was creating a fixed function shader generator for the Athena engine. I kept using strcat() with if statements, and in a lot of places I kept using sprintf() then copying that in with strcat(). So I decided to make SprintfCat(), all the wonderful joy of sprintf, with the [...]]]></description>
			<content:encoded><![CDATA[<p>On the train to Cardiff yesterday, I was creating a fixed function shader generator for the Athena engine. I kept using strcat() with if statements, and in a lot of places I kept using sprintf() then copying that in with strcat().</p>
<p>So I decided to make SprintfCat(), all the wonderful joy of sprintf, with the ability to concatenate with a already existant string like strcat.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="cpp" style="font-family:monospace;"><span class="co1">//</span>
<span class="co1">//</span>
<span class="kw4">size_t</span> ath<span class="sy4">::</span><span class="me2">SprintfCat</span><span class="br0">&#40;</span> <span class="kw4">char</span> <span class="sy2">*</span> inoutBuffer, <span class="kw4">const</span> <span class="kw4">size_t</span> inBufferSize, <span class="kw4">const</span> <span class="kw4">char</span> <span class="sy2">*</span> inFormat, ... <span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw4">const</span> <span class="kw4">size_t</span> offset <span class="sy1">=</span> StrLen<span class="br0">&#40;</span> inoutBuffer <span class="br0">&#41;</span><span class="sy4">;</span>
	<span class="kw4">size_t</span> ret <span class="sy1">=</span> <span class="nu0">0</span><span class="sy4">;</span>
	<span class="kw4">va_list</span> arg<span class="sy4">;</span>
&nbsp;
	<span class="co1">//</span>
	<span class="kw3">va_start</span><span class="br0">&#40;</span> arg, inFormat <span class="br0">&#41;</span><span class="sy4">;</span>
	<span class="br0">&#123;</span>
		ret <span class="sy1">=</span> VSprintf<span class="br0">&#40;</span> inoutBuffer <span class="sy2">+</span> offset, inBufferSize <span class="sy2">-</span> offset, inFormat, arg <span class="br0">&#41;</span><span class="sy4">;</span>
	<span class="br0">&#125;</span>
	<span class="kw3">va_end</span><span class="br0">&#40;</span> arg <span class="br0">&#41;</span><span class="sy4">;</span>
&nbsp;
	<span class="co1">//</span>
	<span class="kw1">return</span> offset <span class="sy2">+</span> ret<span class="sy4">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>I had already created my own wrappers around strlen() and vsprintf(), the reason being the fault of Microsoft. With their implementation of the standard library, they decided to deprecate non-safe versions complain at you until you either used their own _s variants, or defined a certain preprocessor.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.lastrayofhope.com/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="cpp" style="font-family:monospace;"><span class="co1">//</span>
<span class="co1">//</span>
<span class="kw4">size_t</span> ath<span class="sy4">::</span><span class="me2">VSprintf</span><span class="br0">&#40;</span> <span class="kw4">char</span> <span class="sy2">*</span> outBuffer, <span class="kw4">const</span> <span class="kw4">size_t</span> inBufferSize, <span class="kw4">const</span> <span class="kw4">char</span> <span class="sy2">*</span> inFormat, <span class="kw4">va_list</span> inArgs <span class="br0">&#41;</span>
<span class="br0">&#123;</span>
<span class="co2">#ifndef ATH_PLATFORM_WINDOWS</span>
	<span class="kw1">return</span> vsnprintf<span class="br0">&#40;</span> outBuffer, inBufferSize, inFormat, inArgs <span class="br0">&#41;</span><span class="sy4">;</span>
<span class="co2">#else</span>
	<span class="kw1">return</span> vsprintf_s<span class="br0">&#40;</span> outBuffer, inBufferSize, inFormat, inArgs <span class="br0">&#41;</span><span class="sy4">;</span>
<span class="co2">#endif</span>
<span class="br0">&#125;</span>
&nbsp;
<span class="co1">//</span>
<span class="co1">//</span>
<span class="kw4">size_t</span> ath<span class="sy4">::</span><span class="me2">StrLen</span><span class="br0">&#40;</span> <span class="kw4">const</span> <span class="kw4">char</span> <span class="sy2">*</span> inString <span class="br0">&#41;</span>
<span class="br0">&#123;</span>
	<span class="kw1">return</span> <span class="kw3">strlen</span><span class="br0">&#40;</span> inString <span class="br0">&#41;</span><span class="sy4">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>While I do prefer to have safe versions, their _s variants are not present in the standard and so it makes the code not portable.</p>
<p>I'm still not quite sure about my naming convention for a variable that is an input and an output. While I do like the <strong>in</strong> or <strong>out</strong> prefix, I don't think <strong>inout</strong> looks right, being slightly too long. I wasn't a fan of <strong>io</strong> either. I have however grown to like the truncation of Athena namespace to ath.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lastrayofhope.com/2011/11/02/sprintfcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Last Piece of Coursework</title>
		<link>http://www.lastrayofhope.com/2008/05/16/last-piece-of-coursework/</link>
		<comments>http://www.lastrayofhope.com/2008/05/16/last-piece-of-coursework/#comments</comments>
		<pubDate>Fri, 16 May 2008 23:33:19 +0000</pubDate>
		<dc:creator>Kaluriel</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Red Book]]></category>
		<category><![CDATA[stdlib]]></category>
		<category><![CDATA[University]]></category>

		<guid isPermaLink="false">http://www.lastrayofhope.com/?p=15</guid>
		<description><![CDATA[The last piece of coursework for this semester was handed in finally, just a viva next thursday then I’ve got the summer to program with my friends for our game for release on Steam. I’ve began planning a game engine and reading through the OpenGL Red Book, and an STL book for anything else that [...]]]></description>
			<content:encoded><![CDATA[<p>The last piece of coursework for this semester was handed in finally, just a viva next thursday then I’ve got the summer to program with my friends for our game for release on Steam.</p>
<p>I’ve began planning a game engine and reading through the OpenGL Red Book, and an STL book for anything else that I don”t know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lastrayofhope.com/2008/05/16/last-piece-of-coursework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

