Null Terminated StringsJekyll2020-06-25T15:59:25-07:00http://www.nullterminatedstrings.com/Joshua T. Fisherhttp://www.nullterminatedstrings.com/j.fisher@digipen.edu
http://www.nullterminatedstrings.com/c++/recursive-warning
http://www.nullterminatedstrings.com/c++/recursive-warning2015-11-2T00:00:00-00:002015-11-02T06:02:21-08:00Joshua T. Fisherhttp://www.nullterminatedstrings.comj.fisher@digipen.edu<p>So before I started interning with the fine folks of DigiPen R&D in the Summer of 2015, I was using one of their projects, <a href="http://zilch.digipen.edu/home/">Zilch</a>, as a scripting language in my game Ripple. As a side project I looked into making an Atom plug-in for Zilch.</p>
<p>I didn’t get particularly far, but I got far enough to realize that the code internal to Zilch that finds member functions was broken.</p>
<p>Here’s a snippet from the Zilch source code that was causing my problem.</p>
<figure class="highlight"><pre><code class="language-c--" data-lang="c++"><span class="n">Function</span><span class="o">*</span> <span class="n">BoundType</span><span class="o">::</span><span class="n">FindFunction</span><span class="p">(</span><span class="n">StringParam</span> <span class="n">name</span><span class="p">,</span> <span class="k">const</span> <span class="n">Array</span><span class="o"><</span><span class="n">Type</span><span class="o">*>&</span> <span class="n">parameters</span><span class="p">,</span> <span class="n">Type</span><span class="o">*</span> <span class="n">returnType</span><span class="p">)</span> <span class="k">const</span>
<span class="p">{</span>
<span class="k">const</span> <span class="n">FunctionMultiMap</span><span class="o">*</span> <span class="n">functions</span> <span class="o">=</span> <span class="cm">/* It gets set somehow */</span><span class="p">;</span>
<span class="c1">// Attempt to find the array</span>
<span class="k">const</span> <span class="n">FunctionArray</span><span class="o">*</span> <span class="n">foundFunctions</span> <span class="o">=</span> <span class="n">functions</span><span class="o">-></span><span class="n">findPointer</span><span class="p">(</span><span class="n">name</span><span class="p">);</span>
<span class="c1">// Check if we found any functions by that name at this level</span>
<span class="k">if</span> <span class="p">(</span><span class="n">foundFunctions</span> <span class="o">!=</span> <span class="nb">nullptr</span><span class="p">)</span>
<span class="p">{</span>
<span class="c1">// Look through all the functions found and check if they signatures match.</span>
<span class="c1">// return it if it does.</span>
<span class="p">}</span>
<span class="c1">// If we found nothing...</span>
<span class="k">else</span>
<span class="p">{</span>
<span class="c1">// Check our base type for this function.</span>
<span class="c1">// No other use of returnType exists in the body of this function.</span>
<span class="k">return</span> <span class="k">this</span><span class="o">-></span><span class="n">BaseType</span><span class="o">-></span><span class="n">FindFunction</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">parameters</span><span class="p">,</span> <span class="n">returnType</span><span class="p">);</span>
<span class="p">}</span>
<span class="k">return</span> <span class="nb">nullptr</span><span class="p">;</span>
<span class="p">}</span></code></pre></figure>
<p>Heavily truncated, but essentially this function looks for a function on a BoundType, typically some Zilch class you’ve compiled, based on name, an array of parameter types, and return type. The problem lies in the fact that at the time, this code never actually looked for returnType. But we never got an unused parameter warning because the returnType was being used, in the recursive call into this function!</p>
<p>Wow, okay, well that’s an interesting problem to run into. Took me an hour or two to find, and <a href="http://motleycoder.com/">the guy who eventually became my boss</a> and I had a good laugh. His tests were actually relying on this bug, so that required some fixing on his part.</p>
<p>But then I gave this some more thought, and I wondered why this wasn’t tracked by MSVC. So I went and tested it on the pre-release VC 2015 compiler. Turned out it still didn’t work. So I messaged <a href="http://nuwen.net/stl.html">STL</a> on reddit, and he suggested I file a Connect bug. <a href="https://connect.microsoft.com/VisualStudio/feedback/details/1189216">So I did.</a></p>
<p>But then I decided to make a test case for any given compiler and see if any of the compilers I would typically consider using solved this, and it turns out they don’t.</p>
<p>Here’s the test code:</p>
<figure class="highlight"><pre><code class="language-c--" data-lang="c++"><span class="cp">#include <iostream>
</span><span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span>
<span class="kt">int</span> <span class="nf">Recursive</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">notUsed</span><span class="p">);</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">notUsedLocal</span> <span class="o">=</span> <span class="s">"Not used"</span><span class="p">;</span>
<span class="n">cout</span> <span class="o"><<</span> <span class="s">"Test: "</span>
<span class="o"><<</span> <span class="n">Recursive</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">notUsedLocal</span><span class="p">)</span>
<span class="o"><<</span> <span class="n">endl</span><span class="p">;</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="kt">int</span> <span class="nf">Recursive</span><span class="p">(</span><span class="kt">int</span> <span class="n">num</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">notUsed</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">if</span> <span class="p">(</span><span class="n">num</span> <span class="o">></span> <span class="mi">5</span><span class="p">)</span>
<span class="k">return</span> <span class="n">num</span><span class="p">;</span>
<span class="k">else</span>
<span class="k">return</span> <span class="n">Recursive</span><span class="p">(</span><span class="o">++</span><span class="n">num</span><span class="p">,</span> <span class="n">notUsed</span><span class="p">);</span>
<span class="p">}</span></code></pre></figure>
<p>And the flags I used to compile on g++ (5.2.0), clang (3.7) and Borland (Embarcadero) (6.50):</p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash">g++ <span class="nt">-Wunused-parameter</span> source.cpp <span class="nt">-o</span> gccOut.exe
clang++ <span class="nt">-Wunused-parameter</span> source.cpp <span class="nt">-o</span> clangOut.exe
bcc32 <span class="nt">-w</span> source.cpp</code></pre></figure>
<p>None of them reported it.</p>
<p>So if you’re interested in getting this fixed for the compilers you might use, let people know, and contact them through these bug reports:</p>
<p>Bug Reports:</p>
<p><a href="https://connect.microsoft.com/VisualStudio/feedback/details/1189216">MSVC++</a></p>
<p><a href="https://llvm.org/bugs/show_bug.cgi?id=25425">clang</a></p>
<p><a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68230">g++</a></p>
<p><a href="http://www.nullterminatedstrings.com/c++/recursive-warning">Unused Arguments Aren't a Problem When Recursing Right?</a> was originally published by Joshua T. Fisher at <a href="http://www.nullterminatedstrings.com">Null Terminated Strings</a> on November 02, 2015.</p>
http://www.nullterminatedstrings.com/projects/PixieSkate
http://www.nullterminatedstrings.com/projects/PixieSkate2015-09-1T00:00:00-00:002015-09-01T06:55:21-07:00Joshua T. Fisherhttp://www.nullterminatedstrings.comj.fisher@digipen.edu<p>Team Skate is working on Pixie Skate. We’re still working on prototyping and moving those prototypes into our engine so there aren’t any videos yet. The general idea is to capture some</p>
<p>My responsibilities on the project were as such:</p>
<ul>
<li>
<p>Tech Director and Build Master</p>
</li>
<li>
<p>Maintaining and extending our build system.</p>
</li>
<li>
<p>Maintaining the core engine.</p>
</li>
<li>
<p>Creating and maintaining WWise integration.</p>
</li>
<li>
<p>Maintaining the component/composition system.</p>
</li>
<li>
<p>Creating and maintaining the input systems.</p>
</li>
<li>
<p>Binding our engine to Zilch, a scripting language we use for some game play code.</p>
</li>
<li>
<p>Utilitizing the reflection system provided by Zilch to automatically serialize/deserialize both our Zilch and C++ components.</p>
</li>
<li>
<p>Working with our Editor programmer to create a quality inteface for designers to develop our game with. We’re using Qt for this.</p>
</li>
</ul>
<p>Tools and Languages used in these tasks:</p>
<ul>
<li>
<p>C++</p>
</li>
<li>
<p>CMake Script</p>
</li>
<li>
<p>Zilch</p>
</li>
<li>
<p>Python</p>
</li>
</ul>
<p><a href="http://www.nullterminatedstrings.com/projects/PixieSkate">Pixie Skate</a> was originally published by Joshua T. Fisher at <a href="http://www.nullterminatedstrings.com">Null Terminated Strings</a> on September 01, 2015.</p>
http://www.nullterminatedstrings.com/prebuild/prebuild-intro
http://www.nullterminatedstrings.com/prebuild/prebuild-intro2015-01-16T00:00:00-00:002015-01-16T06:55:21-08:00Joshua T. Fisherhttp://www.nullterminatedstrings.comj.fisher@digipen.edu<p>This is the first in a series of articles I plan to write about the build process in software development. I have friends who’ve taught me more about it than I care to admit, and have written much better articles about it. However I can’t write about the systems I’ve used and learned about without writing a bit on why you should think about using them.</p>
<p>So, developing software is a pretty large task. I know that may seem obvious, but it’s important to know the steps involved so that you can reduce, and ideally automate, the tedious work. When you first start on a project, maybe you decide on a directory structure, this can change, but you do need to decide on something, even if it’s the old “everything in one folder” method. Once you do that you write some code. And if you’re a professional, it’s probably in multiple files, and you’ll likely have some external and internal dependencies.</p>
<p>##Definitions</p>
<p>Let’s define those quickly so there’s no confusion:</p>
<p><u>External Dependency</u>: You have a library like SDL, Boost, or GLFW you need to link to. Could be static or dynamic, ultimately it doesn’t matter. The point is that this is code you’re not compiling yourself. You need to keep track of these binary files, and the different versions for different compilers and platforms you might be supporting.</p>
<p><u>Internal Dependency</u>: Code that you compile yourself, into either a dynamic or static library. You still need to keep track of the dynamic files during the packaging step, but considering you’ll be doing one compile per platform, this is much easier than doing so with your external dependancies. These files won’t be kept in your repository and thus are only generated and worried about at compile/runtime.</p>
<p>##Why and How</p>
<p>And now you have your first problem. How do you build this thing? You envisioned this as a multi platform program, but you don’t want to write a make file from scratch for every compiler you might need. You’ll have to edit it every time you make a new cpp. Besides, I have Visual Studio users on my team, they want to use the tool they know. Plus that person who does our Mac ports needs to be able to use XCode.</p>
<p>This is where a Prebuild system comes into play. I want to be clear that I’m not actually trying to bash make here. Make is great, I’ve used it with three compilers before, and it’s a champ. But if you want to use something like Visual Studio, you get nothing out of using make. I mean you can go through the Visual Studio wizard and make a project alongside your makefile, but now you have two things to keep up to date. What a Prebuild system does is allow you to define all the things you’d do with make or Visual Studio solutions/projects, but in one “language” so it’s consistent. And in return you get to generate the project you’d like to work on at the moment.</p>
<p>Feel like working with Vi/emacs and the terminal today? Generate a makefile project and start your coding/building. Person on Windows wants to use Visual Studio? They’ll generate the appropriate files based on their preferred version and get going at it.</p>
<p>Now it’s never as easy as that. Your code and all of your libraries need to be cross platform, so don’t go using obscure C++14 stuff if your Windows devs are stuck on VS 2013 or lower. (Even 2015 won’t support everything in C++11, let alone 14). And you’ll generally need to handle a bunch of edge cases depending on platform and/or compiler. So makefile hell is not beneath you, as this is arguably worse.</p>
<p>##Plans
I will be writing articles around various Prebuild systems I’ve used or plan to try out. I’ll be working through various projects I’ve worked on and show off various Prebuild strategies. Here are the first few I plan to do over with links to their official sites:</p>
<ul>
<li><a href="cmake.org">CMake</a></li>
<li><a href="http://industriousone.com/premake">Premake</a>
I recommend using <a href="http://sourceforge.net/projects/premake/files/Premake/nightlies/">this instead.</a> As it contains binaries of the newest builds of premake.</li>
<li><a href="http://www.fastbuild.org/">FASTBuild</a></li>
</ul>
<p>Now FASTBuild is not technically a Prebuild system, or cross platform, but they’ve got generating Visual Studio solutions from meta files in, and they’re looking at doing cross platform. So it looks like it’s becoming a hybrid of both a Prebuild and builder system. It’s also really fast during the build step, utilizing a concept called “Unity builds” that sort of appends a bunch of source together into one file so that the compiler just compiles most or all of the project in one go. On many (if not all) compilers this tends to be quicker than actually compiling the files separately into their own object files.</p>
<p>I’ll likely go over more in time, I know I want to talk about the build process at some point, talking about the flags in the cl compiler (the compiler Microsoft provides in Visual Studio) that might interest you folks, but this is my current roadmap. Thanks for reading, check back soon for my series on how to get started with CMake!</p>
<p>##References
<a href="http://www.trentreed.net/wp/?p=102">Trent Reed</a> has a really great write up on Build systems with some fantastic diagrams</p>
<p><a href="http://www.nullterminatedstrings.com/prebuild/prebuild-intro">An Introduction to Prebuild Systems (As they pertain to C & C++)</a> was originally published by Joshua T. Fisher at <a href="http://www.nullterminatedstrings.com">Null Terminated Strings</a> on January 16, 2015.</p>
http://www.nullterminatedstrings.com/projects/Ripple
http://www.nullterminatedstrings.com/projects/Ripple2014-11-2T00:00:00-00:002014-09-01T06:55:21-07:00Joshua T. Fisherhttp://www.nullterminatedstrings.comj.fisher@digipen.edu<iframe width="560" height="315" src="https://www.youtube.com/embed/gUoXGoufYhE?controls=0" frameborder="0" allowfullscreen=""></iframe>
<p>The Adjective Noun completed Ripple during June of 2015, a “Poetic Experience” game.</p>
<p>My responsibilities on the project were as such:</p>
<ul>
<li>
<p>Tech Director and Build Master</p>
</li>
<li>
<p>Maintaining and extending our build system.</p>
</li>
<li>
<p>Creating and maintaining the “core” systems that allow our other programmers to develop derivative systems.</p>
</li>
<li>
<p>Maintaining our Component system.</p>
</li>
<li>
<p>Binding our engine to Zilch, a scripting language we use for some game play code.</p>
</li>
<li>
<p>Creating gameplay components when needed.</p>
</li>
</ul>
<p>Tools and Languages used in these tasks:</p>
<ul>
<li>
<p>C++</p>
</li>
<li>
<p>CMake Script</p>
</li>
<li>
<p>Python</p>
</li>
<li>
<p>Zilch</p>
</li>
</ul>
<p><a href="http://www.nullterminatedstrings.com/projects/Ripple">Ripple</a> was originally published by Joshua T. Fisher at <a href="http://www.nullterminatedstrings.com">Null Terminated Strings</a> on September 01, 2014.</p>
http://www.nullterminatedstrings.com/projects/SoularEclipse
http://www.nullterminatedstrings.com/projects/SoularEclipse2014-01-04T00:00:00-00:002014-01-04T06:55:21-08:00Joshua T. Fisherhttp://www.nullterminatedstrings.comj.fisher@digipen.edu<iframe width="560" height="315" src="https://www.youtube.com/embed/A-eomzCX4ic?controls=0" frameborder="0" allowfullscreen=""></iframe>
<p>Soular Eclipse was my second game at DigiPen, this time written in C, and I took a more backseat role on this team after a hellish first semester. I primarily managed the teams premake build system and built the game object and memory managers.</p>
<p>The memory manager was a basic fixed-size free-list page-based memory manager. Unfortunately I never got it quite right, and the game shipped with quite a bug in it. It was still usable, but a huge portion of it’s functionality was unaccessable due to some pointer math errors I couldn’t root out. Perhaps we’ll explore the fixing of this manager in the future?</p>
<p><a href="http://www.nullterminatedstrings.com/projects/SoularEclipse">Soular Eclipse</a> was originally published by Joshua T. Fisher at <a href="http://www.nullterminatedstrings.com">Null Terminated Strings</a> on January 04, 2014.</p>
http://www.nullterminatedstrings.com/projects/TitleOfGame
http://www.nullterminatedstrings.com/projects/TitleOfGame2013-09-01T00:00:00-00:002013-09-01T06:55:21-07:00Joshua T. Fisherhttp://www.nullterminatedstrings.comj.fisher@digipen.edu<iframe width="560" height="315" src="https://www.youtube.com/embed/w-jULUaIg7c?controls=0" frameborder="0" allowfullscreen=""></iframe>
<p>My primary contributions were the menus and camera. I’m particularly proud of the shape creation work I did. The shape creation used some basic custom serialization to dynamically create the right click menus. I used a general tree structure I wrote in Python to generate the menus at level-load, and just placed them based on player position.</p>
<p><a href="http://www.nullterminatedstrings.com/projects/TitleOfGame">Title of Game</a> was originally published by Joshua T. Fisher at <a href="http://www.nullterminatedstrings.com">Null Terminated Strings</a> on September 01, 2013.</p>