<?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>Spiralstorm Games &#187; C/C++</title>
	<atom:link href="http://spiralstormgames.com/blog/category/cc/feed/" rel="self" type="application/rss+xml" />
	<link>http://spiralstormgames.com/blog</link>
	<description>Game Development, Flash, iPhone</description>
	<lastBuildDate>Tue, 16 Aug 2011 03:13:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.2</generator>
		<item>
		<title>Pixelwave is officially released!</title>
		<link>http://spiralstormgames.com/blog/iphone-games/pixelwave-is-officially-released/</link>
		<comments>http://spiralstormgames.com/blog/iphone-games/pixelwave-is-officially-released/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 21:21:19 +0000</pubDate>
		<dc:creator>Oz</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[App Store]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Pixelwave]]></category>
		<category><![CDATA[iPhone Games]]></category>
		<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://spiralstormgames.com/blog/?p=410</guid>
		<description><![CDATA[h4 { font-weight: bold; font-size: 18px; margin: 20px 0 10px 0; } Wow, it&#8217;s been a while since we first revealed Pixelwave. I&#8217;m delighted to announce that Pixelwave is now publicly available to everyone. Today marks the official birth day of Pixelwave as it leaves the warm womb of the private beta phase and enters the <a href="http://spiralstormgames.com/blog/iphone-games/pixelwave-is-officially-released/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-games%2Fpixelwave-is-officially-released%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-games%2Fpixelwave-is-officially-released%2F&amp;source=spiralstorm&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<style>
h4 {
font-weight: bold;
font-size: 18px;
margin: 20px 0 10px 0;
}
</style>
<p>Wow, it&#8217;s been a while since we <a href="http://spiralstormgames.com/blog/iphone-games/say-hi-to-pixelwave-for-the-iphone/">first revealed Pixelwave</a>. I&#8217;m delighted to announce that Pixelwave is now <a href="http://www.pixelwave.org/">publicly available</a> to everyone.</p>
<p>Today marks the official birth day of Pixelwave as it leaves the warm womb of the private beta phase and enters the real world. We are very thankful to our awesome testers who gave us priceless feedback and support. But, as Simon would say, enough with all the self-indulgent nonsense. What are you waiting for? <a href="http://www.pixelwave.org/download">Give it a go</a>.</p>
<p style="text-align: center;"><a href="http://www.pixelwave.org"><img class="aligncenter size-full wp-image-464" style="margin-top: 20px; margin-bottom: 20px; border: 4px solid #dddddd;" title="PixelwavePoster" src="http://spiralstormgames.com/blog/wp-content/uploads/2011/08/PixelwavePoster1.jpg" alt="" width="609" height="465" /></a></p>
<h4><strong>Where do I start?</strong></h4>
<p>We&#8217;ve created a comprehensive <a href="http://www.pixelwave.org/docs">documentation center</a> to help ease the learning curve as much as possible.</p>
<p>Your very first step should probably be the <a href="http://www.pixelwave.org/docs/Getting_Started_Guide">getting started guide</a>.</p>
<h4>What&#8217;s Pixelwave all about?</h4>
<p>Pixelwave is the framework we&#8217;ve always wanted to use. It lets you easily create fast, efficient, hardware-accelerated 2D games and interactive applications for iOS. Being game developers with a background in web, we were inspired to model it after the ActionScript 3 API.</p>
<p>Pixelwave was designed with the following goals in mind:</p>
<ul>
<li><strong>Speed</strong> &#8211; We try to get the most out of the device by coding all the core stuff in C and doing lots of invisible OpenGL optimizations.</li>
<li><strong>Simplicity</strong> &#8211; Above all, we believe a great framework must be easy to use. Pixelwave&#8217;s interface is written in pure object-oriented Objective-C. We labored over each class, method, and property name to create an intuitive and accessible interface.</li>
<li><strong>Documentation</strong> &#8211; At the end of the day, even the greatest open source project would be unusable by most without proper documentation. We&#8217;re <a href="http://www.pixelwave.org/docs">actively trying</a> to avoid that.</li>
<li><strong>Open source</strong> &#8211; What started out as a small internal project has already grown into something much bigger. We&#8217;re thrilled to see where the open source community can take this project now that it&#8217;s <a href="http://www.github.com/spiralstorm/Pixelwave">out in the wild</a>.</li>
</ul>
<p>You can read more about the ideas behind Pixelwave in the <a href="http://www.pixelwave.org/docs/Introduction_to_Pixelwave">5 minute intro to Pixelwave</a> over at the documentation center.</p>
<h4><strong>What can I do with it?</strong></h4>
<p>Pixelwave is all about creating interactive 2D games and applications that need to be fast and efficient.</p>
<p>If you want to create a clone of Mail, for example, you&#8217;re probably better off using UIKit. But if you&#8217;re looking to make a real-time hardware-accelerated 2D game, Pixelwave is the right tool for the job.</p>
<p>You can learn more about Pixelwave&#8217;s capabilities in the <a href="http://www.pixelwave.org/docs/Manual">hulky manual</a>.</p>
<h4>Who&#8217;s using it?</h4>
<p>Though the framework is still in its early stages, Pixelwave&#8217;s private beta has already produced a couple of App Store games (<a href="http://42games.net/introducing-sneak-out-ios-game/">Sneak Out!</a>, <a href="http://itunes.apple.com/us/app/kickbox/id438373028?mt=8&amp;uo=4">KickBox</a>), some <a href="http://area-161.com/2011/05/04/project-darts-update/">in-development</a> <a href="http://www.mindjuice.net/2010/12/03/introducing-pixelwave/">projects</a>, and there&#8217;s even a class <a href="http://www.pixelwave.org/forums/discussion/comment/128/#Comment_128">being taught with it</a>.</p>
<h4><strong>What does it come with?</strong></h4>
<p><strong> </strong></p>
<p>When you <a href="http://www.pixelwave.org/download">download PIxelwave</a> you get:</p>
<ul>
<li>The Pixelwave framework.</li>
<li>The PixelKit framework, which adds useful tools for game developers.</li>
<li>A bunch of samples to get you started.</li>
<li>Several useful Xcode templates.</li>
<li>A complete API reference (Including a native Xcode docset).</li>
</ul>
<p>And there&#8217;s always the <a href="http://www.pixelwave.org/docs">documentation center</a> with lots of yummy articles.</p>
<h4><strong>And all of this is free?</strong></h4>
<p><strong> </strong></p>
<p>Yep, it&#8217;s available under the (very) permissive <a href="http://www.gzip.org/zlib/zlib_license.html">zlib license</a>. Why? Because we believe in the power of open source.</p>
<h4>In conclusion</h4>
<p>This is the start of something pretty big. We have high hopes for this framework and hope you enjoy it as much as we intended you to. So feel free to join the <a href="http://www.pixelwave.org/forums">forums</a>, <a href="http://twitter.com/oztune">follow us</a>, <a href="http://www.github.com/spiralstorm/Pixelwave">fork us</a>, tweet about us, and help us get the word out about Pixelwave.</p>
<p>Cheers!</p>
]]></content:encoded>
			<wfw:commentRss>http://spiralstormgames.com/blog/iphone-games/pixelwave-is-officially-released/feed/</wfw:commentRss>
		<slash:comments><span class="dsq-postid" rel="410 http://spiralstormgames.com/blog/?p=410">2</span></slash:comments>
		</item>
		<item>
		<title>Say hi to Pixelwave for the iPhone</title>
		<link>http://spiralstormgames.com/blog/iphone-games/say-hi-to-pixelwave-for-the-iphone/</link>
		<comments>http://spiralstormgames.com/blog/iphone-games/say-hi-to-pixelwave-for-the-iphone/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 17:20:14 +0000</pubDate>
		<dc:creator>Oz</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Flash Games]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[iPhone Games]]></category>
		<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://spiralstormgames.com/blog/?p=158</guid>
		<description><![CDATA[Today I&#8217;m really excited to introduce something we&#8217;ve been working on for quite a while here at Spiralstorm. It&#8217;s called Pixelwave and it&#8217;s a complete framework for building 2D games and applications on the iPhone, based completely on the Flash AS3 API. Pixelwave The idea started around mid-2009 when we realized that there really weren&#8217;t <a href="http://spiralstormgames.com/blog/iphone-games/say-hi-to-pixelwave-for-the-iphone/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-games%2Fsay-hi-to-pixelwave-for-the-iphone%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-games%2Fsay-hi-to-pixelwave-for-the-iphone%2F&amp;source=spiralstorm&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Today I&#8217;m really excited to introduce something we&#8217;ve been working on for quite a while here at Spiralstorm.</p>
<p>It&#8217;s called Pixelwave and it&#8217;s a complete framework for building 2D games and applications on the iPhone, based completely on the Flash AS3 API.</p>
<div style="text-align: center; margin: 20px 0;">
<div style="border: 1px solid #cbcbcb; padding: 10px; width: 481px;"><img class="alignnone size-full wp-image-170" title="Pixelwave Logo" src="http://spiralstormgames.com/blog/wp-content/uploads/2010/02/Logo.png" alt="" width="481" height="119" /></div>
</div>
<div style="font-weight: bold; font-size: 18px; margin: 20px 0 10px 0;">Pixelwave</div>
<p>The idea started around mid-2009 when we realized that there really weren&#8217;t any good 2D engines out there for the iPhone that wrap OpenGL ES in a clean, object orientated framework, while running in a really fast, optimized way.</p>
<p>We&#8217;ve also been using Flash for ages, and decided to start out by using the same class and function names used in Flash to make our lives easier.</p>
<p>The engine has come a really long way since, actually getting overhauled twice until we had something we&#8217;re really happy with.</p>
<blockquote><p>Our main goals were ease-of-use and optimized rendering. The end result is an optimized C-based core, with an easy to use Objective-C interface.</p></blockquote>
<p>The framework now replicates a lot of the core functionality of Flash in Objective-C. We chose to go with Objective-C over C or C++ because of it&#8217;s inherent similarities to Actionscript 3, at least as far as sharing the same concepts for classes/interfaces/methods in a very clean and simple API.</p>
<p>To keep things as fast as possible though, the engine&#8217;s core is built completely in C, and wraps OpenGL very intelligently, doing a lot of optimizations for the user for free.</p>
<p>So when we realized just what an awesome tool this creation has become, we decided we need to share it with the world, and open-source it for everyone!</p>
<p><strong>So lets talk features. Here are the big ones:</strong></p>
<ul>
<li>Super optimized OpenGL rendering. You just tell Pixelwave where to draw, it&#8217;ll take care of the rest <img src='http://spiralstormgames.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li> Very clean API, following the Flash ActionScript 3.0 framework structure.</li>
<li>Simple event dispatching model, just like Flash. Event bubbling and capture phase included.</li>
<li>Handles native iPhone features with style. (ex: Listen to touch events just like you would mouse events in Flash, very intuitive)</li>
<li>Native vector drawing, using the Graphics class</li>
<li>TextFields with native or custom fonts.</li>
<li>One line texture loading, supporting many different texture types</li>
<li>Simple sound playback</li>
<li>Very easy to extend the engine&#8217;s functionality (if you know OpenGL) by subclassing the DisplayObject</li>
<li>Plays nice with Cocoa Touch, contained completely within a single UIView</li>
</ul>
<div style="font-weight: bold; font-size: 18px; margin: 20px 0 10px 0;">PixelKit: Just for games</div>
<p>So we know all those features are awesome for general use, but seeing as we are all about creating games we thought we&#8217;d also share our useful utility classes specialized for games. Since these aren&#8217;t a part of the core engine we grouped them into the PixelKit, a collection of classes for game makers to use with Pixelwave. It&#8217;ll all be in the same package, pre-integrated for everyone to enjoy.</p>
<p>Main PixelKit features:</p>
<ul>
<li> Resource Manager &#8211; An efficient, object-oriented resource manager that can handle any file type + sync/async loading</li>
<li>Animation Importer &#8211; Turn your Flash MovieClips into PixelKit AnimationClips with the PixelKit animation importer and the Flash animation exporter (more on that below)</li>
<li>Tweening engine &#8211; A must for any real app, integrated with PIxelwave</li>
<li> A Particle System &#8211; An optimized particle system for use with Pixelwave</li>
<li> Physics engine bindings &#8211; We like Box2D</li>
</ul>
<div style="font-weight: bold; font-size: 18px; margin: 20px 0 10px 0;">Flash animations on the iPhone</div>
<p>The Flash exporting conversion tool is another, completely separate app we&#8217;ve been working on for a while. It lets you turn your Flash animations into PixelKit AnimationClips, and control them with commands like gotoAndPlay, gotoAndStop, etc. We&#8217;re going to keep this one on the down-low for now, expect more info on this in the future.</p>
<div style="font-weight: bold; font-size: 18px; margin: 20px 0 10px 0;">Code Examples</div>
<p>This framework shines when it comes to code. Things that would take dozens or hundreds of lines before can be achieved in only a few. Whether you&#8217;re familiar with the Flash API or not, this framework provides a clean, easy-to-learn API that just makes sense.</p>
<p>Creating a vector shape:</p>
<pre>PXShape *shape = [PXShape new];
[shape.graphics lineStyle: 1];
[shape.graphics drawRect: 0 : 0 : 100 : 100];

shape.x = 50;
shape.y = 50;
shape.rotation = 45;

[self addChild: shape];
[shape release];</pre>
<p>Loading and displaying an image:</p>
<pre>PXTexture *smiley = [PXTexture textureWithFileName: @"smiley.png"];
[self addChild: smiley];</pre>
<p>Listening to an event:</p>
<pre>[self addEventListener: PX_TOUCH_EVENT_DOWN listener: PXListener(onSmileyTouch:)];

- (void) onSmileyTouch: (PXTouchEvent *)e{
    smiley.x = e.localX;
    smiley.y = e.localY;
}</pre>
<p>If you&#8217;re a Flash developer, we also want to know what you DON&#8217;T like about Flash. Yup, we figured if we&#8217;re already getting our hands dirty we might as well fix those little nuances that drive us crazy with Flash every day. For example, in AS3 you probably find yourself writing this alot:</p>
<pre>sprite.scaleX = sprite.scaleY = 0.5;</pre>
<p>Well, in Pixelwave the DisplayObject has an extra, derived property called &#8216;scale&#8217;. Changing scale modifies both the scaleX and scaleY property.</p>
<pre>sprite.scale = 0.5;</pre>
<div style="font-weight: bold; font-size: 18px; margin: 20px 0 10px 0;">A Brief Conclusion</div>
<p>As you can see we&#8217;ve been very busy here at the Spiralstorm offices. We&#8217;ve been developing all these tools for internal use, but we think the community can take them to places we&#8217;ve never even imagined. Everything will be open-source, I can&#8217;t wait to see what will happen.</p>
<p>So please, tell us what you think! We&#8217;re nearing the beta testing stage soon.<br />
If you want to help us test all this, please <a href="http://www.spiralstormgames.com/contact.htm">contact us</a>. We&#8217;ll keep you updated.</p>
<p>I, (Oz) also have the great honor of speaking at <a href="http://www.360flex.com/">360|Flex</a> and <a href="http://www.360idev.com/">360|iDev</a> these upcoming two months, and guess what I&#8217;ll be demoing&#8230;<br />
If you&#8217;re going to be attending 360|Flex or 360|iDev (and you should in any case), come check it out!</p>
<p>We also have a new dedicated site: <a href="http://www.pixelwave.org" target="_blank">www.pixelwave.org</a></p>
<p><strong>Progress update</strong>: <a href="http://spiralstormgames.com/blog/news/pixelwave-update/">read more</a></p>
]]></content:encoded>
			<wfw:commentRss>http://spiralstormgames.com/blog/iphone-games/say-hi-to-pixelwave-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments><span class="dsq-postid" rel="158 http://spiralstormgames.com/blog/?p=158">8</span></slash:comments>
		</item>
		<item>
		<title>Polygon Triangulation</title>
		<link>http://spiralstormgames.com/blog/cc/triangulation/</link>
		<comments>http://spiralstormgames.com/blog/cc/triangulation/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 23:27:34 +0000</pubDate>
		<dc:creator>Oz</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://spiralstormgames.com/blog/?p=137</guid>
		<description><![CDATA[If you&#8217;re using OpenGL, you may have a need to triangulate your polygons in order to draw them. A common algorithm to do this is the ear clipping algorithm. We&#8217;ve been on the search for a solid implementation of this for a while, and have finally found one: http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml It&#8217;s written in c++ and has <a href="http://spiralstormgames.com/blog/cc/triangulation/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fcc%2Ftriangulation%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fcc%2Ftriangulation%2F&amp;source=spiralstorm&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If you&#8217;re using OpenGL, you may have a need to triangulate your polygons in order to draw them.</p>
<p>A common algorithm to do this is the ear clipping algorithm. We&#8217;ve been on the search for a solid implementation of this for a while, and have finally found one:</p>
<p><a href="http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml" target="_blank">http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml</a></p>
<p>It&#8217;s written in c++ and has no dependencies (except for stl). It was really easy to use, and worked well in our tests.</p>
]]></content:encoded>
			<wfw:commentRss>http://spiralstormgames.com/blog/cc/triangulation/feed/</wfw:commentRss>
		<slash:comments><span class="dsq-postid" rel="137 http://spiralstormgames.com/blog/?p=137">0</span></slash:comments>
		</item>
		<item>
		<title>Creating unique variables within your preprocessor macros</title>
		<link>http://spiralstormgames.com/blog/iphone-development/creating-unique-variables-within-your-preprocessor-macros/</link>
		<comments>http://spiralstormgames.com/blog/iphone-development/creating-unique-variables-within-your-preprocessor-macros/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 23:15:41 +0000</pubDate>
		<dc:creator>Oz</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://spiralstormgames.com/blog/?p=88</guid>
		<description><![CDATA[Sometimes in your macros you need to use a variable, but you can&#8217;t scope it to the macro. If you use this macro more than one in the same scope you get a duplicate variable warning. For example, let&#8217;s say this is your macro: #define LOOP_10_TIMES \ int i = 0; \ for( i = <a href="http://spiralstormgames.com/blog/iphone-development/creating-unique-variables-within-your-preprocessor-macros/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-development%2Fcreating-unique-variables-within-your-preprocessor-macros%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-development%2Fcreating-unique-variables-within-your-preprocessor-macros%2F&amp;source=spiralstorm&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Sometimes in your macros you need to use a variable, but you can&#8217;t scope it to the macro. If you use this macro more than one in the same scope you get a duplicate variable warning.</p>
<p>For example, let&#8217;s say this is your macro:</p>
<pre class="brush: plain">
#define LOOP_10_TIMES \
int i = 0; \
for( i = 0; i &lt; 10; ++i)
</pre>
<p>And this is your implementation:</p>
<pre class="brush: php">
LOOP_10_TIMES{
	x += i;
}
</pre>
<p>This is fine, but what happens when you want to use this macro twice? Like so:</p>
<pre class="brush: php">
LOOP_10_TIMES
	num += i;

LOOP_10_TIMES
	mun += i;
</pre>
<p>You&#8217;re sure to get a nasty error (or at least a warning).<br />
This is because your code now declares the variable &#8216;i&#8217; twice in the same scope.</p>
<p><span id="more-88"></span></p>
<p>So how do we solve this? Our macro needs to create its own unique variable each time and use that instead. This is where the <strong>__LINE__</strong> preprocessor directive comes into play</p>
<p>Using __Line__ you can figure out what on what line in the file the call to the macro is located. So if you combine the current line with the name of your variable you can create a unique variable which will never repeat within the same source file twice.</p>
<p>So how do you generate a unique variable? Use this handy code:</p>
<pre class="brush: c">
#define _LINENAME_CONCAT( _name_, _line_ ) _name_##_line_
#define _LINENAME(_name_, _line_) _LINENAME_CONCAT(_name_,_line_)
#define _UNIQUE_VAR(_name_) _LINENAME(_name_,__LINE__)
</pre>
<p>You&#8217;re probably wondering why this code does in 3 nested calls what it can do with just one&#8230; well if you consolidate these three lines into one it just won&#8217;t work.. try it out. This works though, I promise.</p>
<p>Ok so now that the hard part is over, here&#8217;s how you use it</p>
<p>So here&#8217;s a little usage example:</p>
<pre class="brush: c">

//Note the line that the code is actually on

int _UNIQUE_VAR(myVar) = 5;
int _UNIQUE_VAR(myVar) = 10;
int _UNIQUE_VAR(myVar) = 20;

//This is what the output is

print( myVar3 ); //output: 5
print( myVar4 ); //output: 10
print( myVar5 ); //output: 20
</pre>
<p>I hope that helps you, it took a while to figure out but it&#8217;s definitely useful in a sticky macro situation</p>
]]></content:encoded>
			<wfw:commentRss>http://spiralstormgames.com/blog/iphone-development/creating-unique-variables-within-your-preprocessor-macros/feed/</wfw:commentRss>
		<slash:comments><span class="dsq-postid" rel="88 http://spiralstormgames.com/blog/?p=88">0</span></slash:comments>
		</item>
		<item>
		<title>Calling C functions in your C++ code</title>
		<link>http://spiralstormgames.com/blog/iphone-development/calling-c-functions-in-your-c-code/</link>
		<comments>http://spiralstormgames.com/blog/iphone-development/calling-c-functions-in-your-c-code/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 22:00:37 +0000</pubDate>
		<dc:creator>Oz</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[iPhone development]]></category>

		<guid isPermaLink="false">http://spiralstormgames.com/blog/?p=75</guid>
		<description><![CDATA[Have you ever wanted to call a c function located in one file within a different c++ (.mm / .cpp) file? If you did, you probably know that it can be a royal pain if you don&#8217;t know the trick. So if like me you&#8217;ve been looking for the solution, it&#8217;s very easy! Just use <a href="http://spiralstormgames.com/blog/iphone-development/calling-c-functions-in-your-c-code/" class="more-link">More &#62;</a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-development%2Fcalling-c-functions-in-your-c-code%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspiralstormgames.com%2Fblog%2Fiphone-development%2Fcalling-c-functions-in-your-c-code%2F&amp;source=spiralstorm&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Have you ever wanted to call a c function located in one file within a different c++ (.mm / .cpp) file?</p>
<p>If you did, you probably know that it can be a royal pain if you don&#8217;t know the trick.<br />
So if like me you&#8217;ve been looking for the solution, it&#8217;s very easy! Just use the <strong><em>extern &#8220;C&#8221;</em></strong> keyword (not to be confused with plain <em>extern</em>). Here&#8217;s an example:</p>
<pre class="brush: c">
extern &quot;C&quot; #include &quot;my_c_code.h&quot;;
</pre>
<p>This also works with the Objective-C #import keyword:</p>
<pre class="brush: c">
extern &quot;C&quot; #import &quot;MyObjCClass.h&quot;;
</pre>
<p>or alternatively for multiple includes</p>
<pre class="brush: c">
extern &quot;C&quot; {
#include &quot;my_c_code.h&quot;
#include &quot;my_other_c_code.h&quot;
}
</pre>
<p>And that&#8217;s the way you include someone else&#8217;s C code into your C++ files. <strong>Easy</strong>!</p>
<p>But&#8230;<br />
If you&#8217;re writing brand new C code and you want it to be automatically compatible with other C++ code you can build it in a way that will make it #include&#8217;able into any source file.</p>
<p>Using the __cplusplus preprocessor variable you can check if the current build target is a c++ file and if so, surround your code with extern &#8220;C&#8221;</p>
<p>So for example let&#8217;s say this is our current C header file:</p>
<pre class="brush: c">

//my_c_header.h:

int addOne(int n);
int globalVar;
//..etc
</pre>
<p>To make this code C++ friendly, we&#8217;d do this:</p>
<pre class="brush: c">
//my_cpp_friendly_c_header.h:

#ifdef __cplusplus
extern &quot;C&quot; {
#endif

int addOne(int n);
int globalVar;
//..etc

#ifdef __cplusplus
}
#endif
</pre>
<p>Now in your C++ file you can just write</p>
<pre class="brush: c">

// my_cpp_code.cpp

#include &quot;my_cpp_friendly_c_header.h&quot;
</pre>
<p>So if you know that your C code will be included into C++ source, it&#8217;s always a good idea to wrap it in extern &#8220;C&#8221; { &#8230; } to avoid headaches later on&#8230;</p>
<p>More info over at: <a href="http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html">http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://spiralstormgames.com/blog/iphone-development/calling-c-functions-in-your-c-code/feed/</wfw:commentRss>
		<slash:comments><span class="dsq-postid" rel="75 http://spiralstormgames.com/blog/?p=75">0</span></slash:comments>
		</item>
	</channel>
</rss>

