C++ Weekly - Ep 61 - Storage Duration with Lambdas

Another way that one might create a stateful lambda in C++11 by manipulating the storage duration of the variables in the lambda.



C++ Weekly - Ep 60 - std::quoted

std::quoted - probably one of the most overlooked parts of the standard library.



C++ Weekly - Ep 59 - Negative Cost Embedded C++ - Part 2

I continue my series on embedded C++ with an example of how we can merge register accesses and save a few more bytes.



C++ Weekly - Ep 58 - Negative Cost Embedded C++ - Part 1

I continue my series on embedded C++ with an example of how templates and constexpr can provide flexibility while reducing the compile size and increasing performance.



C++ Weekly - Ep 57 - Dissecting An Optimization

In this episode I dissect an optimization that’s unique to Clang.



C++ Weekly - Ep 56 - Zero Cost Embedded C++ - Part 3

We conclude the first part of our series on the MSP430.



C++ Weekly - Ep 55 - Zero Cost Embedded C++ - Part 2

We continue our series on the MSP430 with C++.



C++ Weekly - Ep 54 - Zero Cost Embedded C++ - Part 1

In this episode we get set up with using the latest C++ features to program a chip which has only 2KiB of flash and 128Bytes of RAM available.



C++ Weekly - Ep 53 - Gotos Are Everywhere

In this episode I break down how some C++ features are defined in terms of goto, so we are essentially using goto throughout our code.



C++ Weekly - Ep 52 - C++ To C Compilation

In this episode we play with llvm-cbe, the C back-end for LLVM, which allows us to essentially compile C++ code into C code.



C++ Weekly - Ep 51 - Advanced Stateful Lambdas

In this episode we try to see just how far we can take the idea of a “stateful lambda” by building one that can be manipulated and interacted with from the caller side.



C++ Weekly - Ep 50 - Inheriting Lambdas vs Generic Lambdas

Now that we know why we would inherit lambdas, and merge them into one implementation (to make a visitor, for instance), how and why does this compare to using a generic lambda? What advantage does one have over the other?



C++ Weekly - Ep 49 - Why Inherit From Lambdas?

What is the practical application of for inheriting from lambdas in C++?



C++ Weekly SE - Why 0xFFFFFFFF == 1

Understanding integeral literal sizing and binary arithmetic rules in C and C++.



C++ Weekly - Ep 48 - C++17's Variadic `using`

In this episode I build from episode 40’s discussion on inheriting lambdas and show how several C++17 features (including variadic using declarations) can be combined to create a succinct merging of lambdas.



C++ Weekly - Ep 47 - My Visual C++ Pet Peeve

Last episode I showed you why you should be taking Visual C++ seriously. This episode I show you my personal pet peeve with Visual Studio that has caused many of my portability issues with cross platform development.



C++ Weekly - Ep 46 - Start Using Visual C++

In this episode I demonstrate why you should take Visual C++ seriously and make it a part of your automated build environment.



C++ Weekly - Ep 45 - Compile Time Maze Generator (and Solver)

In this episode I demonstrate how to build a random maze generator (and solver) that can be executed at compile time with constexpr.



C++ Weekly - Ep 44 - constexpr Compile Time Random

In this episode I demonstrate a constexpr enabled random number generator. I then it to generate a different random number sequence each time it is compiled.



C++ Weekly - Ep 43 - Stack Elision?

Is stack elision a thing? What would that imply if it were?



C++ Weekly - Ep 42 - Clang's Heap Elision

In this episode I explore Clang’s ability to elide heap operations.



C++ Weekly - Ep 41 - C++17's constexpr Lambda Support

In this episode I demonstrate how C++17’s support for lambdas in a constexpr context can clean up many constexpr use cases.



C++ Weekly - Ep 40 - Inheriting From Lambdas

In this episode I discuss how (and why) you can inherit from a lambda function along with possible use cases.



C++ Weekly - Ep 39 - C++17's Deduction Guides

C++17’s automatic class template deduction feature brings with it a new sub-feature called “deduction guides” which are used to help the compiler with class template type deduction. I give examples of what they are and how they are used in this episode.



C++ Weekly - Ep 38 - C++17's Class Template Type Deduction

Experimenting with C++17’s class template argument type deduction feature and learning what its limitations are.



C++ Weekly - Ep 37 Stateful Lambdas

Creating stateful lambdas using capture expressions in C++14.



C++ Weekly - Ep 36 Reading Assembly Language - Part 3

Part 3 of our basic introduction to understanding the assembly output from your compiler. In this episode we do some reverse engineering of other non-Intel architectures.



C++ Weekly - Ep 35 Reading Assembly Language - Part 2

Part 2 of our basic introduction to understanding the assembly output from your compiler.



C++ Weekly - Ep 34 Reading Assembly Language - Part 1

Basic introduction to understanding the assembly output from your compiler.



C++ Weekly SE - Visual C++ 1.52 (1993) Review

Review of using Visual C++ 1.52 from 1993. This is the oldest version of Visual C++ available on MSDN.



C++ Weekly - Ep 33 Start Using Default Member Initializers

Why you should use C++11’s default member initializers.



C++ Weekly SE - g++ 2.4.5 (1993) Review

Reviewing g++ 2.4.5 from 1993 on Slackware Linux 1.01.



C++ Weekly - Ep 32 Lambdas For Free

Examining the (free) cost of using lambdas in C++.



C++ Weekly Special Edition - Borland Turbo C++ 3.0 Review - Part 2

In this Special Edition episode I continue my exploration of Borland Turbo C++ 3.0 from 1992.



C++ Weekly - Ep 31 IncludeOS

I explore what IncludeOS is and how you might use it for OS experimentation.



C++ Weekly Special Edition - Borland Turbo C++ 3.0 Review

In this Special Edition episode I explorer Borland Turbo C++ 3.0 from 1992.



C++ Weekly - Ep 30 C++17's [[nodiscard]] Attribute

Wrapping up our C++17 attribute coverage with possibly the most interesting yet: [[nodiscard]].



C++ Weekly - Ep 29 C++17's [[maybe_unused]] Attribute

Using C++17’s new [[maybe_unused]] attribute.



Destructuring Standard Containers in C++17

A comment was made on my YouTube channel that destructuring in C++17 would be much more useful if it worked with standard containers. At the moment I responsed that this would be someone impossible to get right without adding too much overhead.



C++ Weekly - Ep 28 C++17's [[fallthrough]] Attribute

Understanding C++17’s new [[fallthrough]] attribute.



C++ Weekly - Ep 27 C++17 Sequence Container Changes

What changes to expect to the sequence containers (for example, std::vector) in the upcoming C++17.



C++ Weekly - Ep 26 Language Features Removed In C++17

C++17 has not only added many new interesting things, it has removed and deprecated a few outdated features as well.



C++ Weekly - Ep 25 C++17's Aggregate Initializations

Continuing coverage of C++17’s new features with new aggregate initialization of base classes.



C++ Weekly - Ep 24 C++17's Structured Bindings

Our continuing series on C++17’s new features with an introduction to C++17’s structured bindings.



C++ Weekly - Ep 23 C++17's __has_include

I continue my series on C++17’s features with the new __has_include functionality.



C++ Weekly - Ep 22 C++17's Nested Namespaces and `std::clamp`

This week I introduce C++17’s nested namespaces and std::clamp library function.



C++ Weekly - Ep 21 C++17's `if` and `switch` Init Statements

This week I introduce C++17’s new support for if and switch init statements.



C++ Weekly - Ep 20 C++17's Fold Expressions - Introduction

This week I introduce C++17’s fold expressions.



C++ Weekly - Ep 19 C++14 For The Commodore 64

Using modern C++ to write extremely efficient high level programs for the Commodore 64.



C++ Weekly Special Edition - Using C++17's constexpr if

In this SE we follow up episode 18’s constexpr if with some concrete examples of where it can be used in existing code.



C++ Weekly - Ep 18 C++17's constexpr if

This week I preview C++17’s upcoming “constexpr if” functionality.



C++ Weekly - Ep 17 C++17's `std::invoke`

This week I preview one of my favorite up coming new features of C++17: std::invoke.



C++ Weekly - Ep 16 Avoiding `std::bind`

Last week we discussed how to use std::bind. this week we discuss why you should never use std::bind



C++ Weekly - Ep 15 Using `std::bind`

Introduction to std::bind from C++11 and how it can be used.



C++ Weekly - Ep 14 Standard Library Gems: `next` and `exchange`

Two somewhat obscure and surprisingly helpful C++ standard library functions.



C++ Weekly - Ep13 Fibonacci: You're Doing It Wrong

Many of the different ways you might implement a Fibonacci sequence in C++ plus one you’ve probably never considered.



C++ Weekly - Ep12 C++17's std::any

In this episode I introduce std::any from the upcoming proposed C++17 standard.



C++ Weekly - Ep11 std::future Part 2

In this episode I correct some of the details of the “std::future Quick Start” episode while expanding on the info provided.



Folds (ish) In C++11

It is possible to perform some form of the variadic folds that are coming in C++17 with the C++11 and C++14 compilers that we have available today by using just a little bit of creativity.



C++ Weekly - Ep10 Variadic Expansion Wrap-Up

In this episode Jason wraps up what we’ve learned so far about variadic templates and shows some additional techniques to consider.



C++ Weekly - Ep9 std::future Quick-Start

In this episode Jason gives a very fast quick-start to what std::future is and how to use std::async to run a function in another thread.



C++ Weekly - Ep8 C++ Name Demangling

In this episode Jason discusses some of what C++ name mangling is, and how to demangle names at runtime.



C++ Weekly - Ep7 Stop Using std::endl

In this episode Jason quickly tries to convince you to stop using std::endl.



C++ Weekly - Ep6 Intro To Variadic Templates

In this episode I give a brief introduction to C++ variadic templates and cover some compile time and runtime performance considerations.



C++ Weekly - Ep5 Intro To ChaiScript



C++ Weekly - Ep4 Variadic Template Refactor



So You Want to Embed A Scripting Language in Your Application

Note: this article was originally written in 2005. I’m importing some missed content into my new site and this is one of those articles. Much of the information in this article is out of date, but it still has some relevance. To see my personal take on the best way to embed scripting in C++, checkout ChaiScript.



C++ Weekly - Ep3 Intro to clang-tidy



C++ Weekly - Ep2 Cost of Using Statics



C++ Weekly - Ep1 ChaiScript_Parser Initialization Refactor



ChaiScript 6 Years Later

It’s been a little more than a year since our last update.



Template Code Bloat Revisited: A Smaller make_shared

Back in 2008 I wrote an article on template code bloat. In that article I concluded that the use of templates does not necessarily cause your binary code to bloat and may actually result in smaller code! This ended up becoming one of my more significant articles and has been referenced on wikipedia.



Complex Object Initialization Optimization with IIFE in C++11

IIFE (Immediately-Invoked Function Expression) is a common tool used in JavaScript. The idea is to both define an anonymous function and call it in the same expression. The point is to produce a local scope for variables so they do not pollute the global scope.



Make Sure You Provide Virtual Destructors

If you make use of inheritance, it’s likely that you need to provide a virtual destructor for your classes. Modern compilers will warn if you do not, but this is a pretty recent development.



ChaiScript (almost) 5 Years Later

July 13, 2009 Reddit covered Release 1.0 of ChaiScript. Many things changed in the last 5 years. Features added, dependencies removed, and performance increased. With all of the changes, we decided it was time to provide a 5 year retrospective and give the world a second first-look at ChaiScript.



C++11: Auto

We’ve already covered C++11 decltype and why you should start using C++11 features today. Now we will move on to one of the most widely supported C++11 features: the new auto keyword.; auto is supported currently by g++ as of 4.4, clang and msvc since 10. So you are safe using it today if you don’t need to support any older compilers. The auto keyword is used to let the compiler determine the type of a variable. This seemingly simple concept can really help clean up your code in some situations. For example:



Are You Using make_shared Yet?

Recently, while watching the GoingNative conference, I learned about the new std::shared_ptr helper function std::make_shared.



Trigraphs, Digraphs and Alternative Tokens

Quick, which language is the following code written in?



Start Using C++11 Now

Every major platform and compiler now supports some aspect of the new C++ standard accepted in 2011. This means it is currently possible to write code that uses some of C++11 while maintaining cross-platform compatibility. Why should you care?



Double vs. Float, Which is Better?

Neither C++ Coding Standards nor Effective C++ addresses the question of which float point type is best to use and in what situations. There are three floating point types in C and C++:



C++11: Decltype

decltype is a type specifier introduced in C++11. It behaves like a function that evaluates to the type of an object at compile time. This article is helping provide some more background information necessary for the more meatier C++11 articles to come.



C++ Partial Specialization of Templates

In this article we are going to introduce the concept of C++ Template Partial Specialization. This is meant to be just a primer on the topic and not exhaustive. The examples here will be used and referenced in later articles. A series of discussions about C++11, now that the language has been finalized, will be coming shortly. In C++ a template class such as this:



Nobody Understands C++: Part 11: Including Me (aka, Provide Consistent Semantics)

I just spent the better part of the day debugging an insidious little bug. It really shouldn’t have taken that long… I even had unit tests in place that covered the code in question! Right!?



Microsoft's Failing Support For C++

Microsoft recently posted a video on Channel 9 and their blogs describing the upcoming work they have planned for C++. The abstract of the video tries to point out Microsoft’s unfailing devotion to C++ development:



C++ AI FTW

Considering the number of articles and polls we come across asking if C++ is dying or dead combined with the decrease in C++ job posting I have personally noticed, C++ sure is alive and well in the AI frontier. C++ takes or ties the top 27 places at the 2010 Google AI Challenge



Nobody Understands C++: Part 10: C++ Is Not an Object Oriented Programming Language

In the context of the rest of the Nobody Understands C++ series, I feel like this one is redundant. But it seems like it needs to be said. C++ is not an object oriented programming language. C++ is a multi-paradigm language that supports most of the major programming paradigms that have been widely accepted. Specifically, C++ supports:



C++0x Final Committee Draft

As others have pointed out, the Final Committee Draft (FCD) of the next C++ standard is now available for anyone to download.



Upcoming GCC 4.5 Features

GCC 4.5.0 has frozen and the release has made it to thefront page. This is significant to me for 2 main reasons.



Developer Day - Boulder 2009

This past Saturday I attended the Developer Day meeting in Boulder, CO. Overall the day was beneficial and interesting even tho it was more dynamic languages centric and very few things applied directly to my C++ development. I did present ChaiScript during a lightning talk.



Nobody Understands C++: Part 9: Error Handling

I was recently at a talk where the speaker was discussing the history of C++. He argued that one problem with C++ was that its design requirements included backward compatibility with C code, and one fallout of this was the requirement to support all previous types of error handling as well as adding exceptions. That is, C++ supports:



Nobody Understands C++: Part 8: Operator Overloading

There has been much discussion over the years about the usefulness of operator overloading in C++ as well as the ability to get it right.



Understanding the ChaiScript clone Function

In ChaiScript variable assignments create a copy of the object being assigned.



ChaiDraw: Programming Toy and Chaiscript Use Case

I have been working for the past few weeks on ChaiDraw. ChaiDraw is an application that’s both meant as an educational toy and as a showcase for how to effectively use ChaiScript in your application.



ChaiScript: Easy C++ Scripting

Jon and I released the first release of ChaiScript earlier today. ChaiScript is designed to make it trivially easy to use scripting in your C++ application and to expose your C++ to the scripting system.



Online C++ Resources

I often mention books that I use as resources, but rarely websites. It seems, on average, that online C++ resources are lacking. However, there are a few that I have found that provide quite valuable insight.



Using colorgcc in Ubuntu (and other Linux distributions)

colorgcc is an awesome little tool for colorizing the output of gcc and g++, making compiler errors and warnings much easier to spot.



Optimizing Massively Multithreaded C++ Applications - Where's the Output Going?

If you have dozens or hundreds of threads doing work they are probably producing some sort of output. I’m not referring to logger output, but to permanent storage, perhaps in a database. If you cannot store the data as quickly as you produce it, you will eventually run into problems. If you are just barely able to keep up with data storage then your scalability will be limited. In the system I am working on poor database performance caused a cascade of errors, making the root cause very difficult to track down. The queue used to store database inserts was growing so large that it was causing out of memory errors which resulted in news returning null. The library calling new did not check the return value, which then caused a segmentation fault when the library attempted to use the pointer.



Optimizing Massively Multithreaded C++ Applications - Beware of Heap Operations

While debugging my massively multithreaded C++ application I would notice times where the application would seem to pause for a few moments. During one of these pauses I halted the application and attached to it with the debugger (GDB). From within GDB I listed (info threads), switched to (thread ) and looked at the stack (bt) of each thread running. I saw something surprising and very telling. Nearly every single thread that was supposed to be performing work was actually blocked on a mutex inside of either malloc or free.



Optimizing Massively Multithreaded C++ Applications - Watch for Hidden Mutexes

If your application does not scale as your threads increase, you should check the code to make sure there are no hidden mutexes limiting your concurrency.



Optimizing Massively Multithreaded C++ Applications - Don't Forget the Obvious

Let’s not overcomplicate things here. If you have 160 threads all trying to run concurrently, even if they are doing little to no work, they are all still doing some work. There’s no reason to make the threads work harder than they need to. Before we get too far, let’s make sure that our compiler optimizations are enabled. It’s possible that compiler optimizations can obscure debugging information or introduce runtime errors if you are doing things that are “tricky” in your C++ code. Be careful, at the first sign that the optimizations are causing problems, back them off. As far as I know, all optimizations are generally considered to be safe, but add to compile time and to the size of the compiled code. Hopefully, if you read this blog often, you do not try to be too clever in your code and are sticking to the spec. If you do not specify any compiler options to GCC you are telling the compiler to build for i386 architecture with no optimizations. Modern CPU’s have far more capabilities than the i386 and taking advantage of them is a good idea. A good start is to enable the most common optimizations and tune the compiled code for a modern CPU architecture: ` gcc -O2 -mtune=pentium3`



Optimizing Massively Multithreaded C++ Applications - Intro

This is the beginning of short series of articles related to optimizing massively multithreadded C++ applications. I’m not entirely sure what the exact definition of “massively multithreaded” is, but for our purposes, let’s assume at least twice as many threads as CPU cores. Having so many OS level threads may not be the most efficient way of handling concurrency, but it is legitimate if most of your threads spend most of their time waiting. They may be waiting on a timeout, as in a timer thread that fires on regular intervals, or a message processing thread that is waiting on IO. The application that I am currently optimizing and debugging has anywhere from 25 to 165 threads running depending on the current parameters of the system. All of them are waiting on something: timers, network IO or message queue condition variables that signal the arrival of new messages. There were several hurdles to getting this configuration to execute efficiently. For this intro article, I’m going to start with two links that I actually found after I had done most of the optimization, and were not directly useful to me.



Iterators Must Go (aka, Alexandrescu endorses D)

Andrei Alexandrescu gave the keynote speech at Boostcon 2009. The speech’s title was “Iterators Must Go.” I did not have the opportunity to attend this year’s Boostcon, but the slides of the keynote are available online.



What is C++ Virtual Inheritance?

C++ Virtual Methods

In C++, the virtual keyword, when applied to class methods, aids in polymorphism. If a method is declared to be virtual, the most derived version of the method is executed when a call is made. If a method is non-virtual, the specific version that is called depends on how the method is called. If the method is called via a pointer to the base class, the base class method is called, if by the derived class, then the derived method is called. This definition is weak; an example is better, as usual:



Programming With Portability in Mind

Almost a year ago now I promised a series of articles on cross-platform C++. Since then, I have finished porting a relatively large C++ project that I wrote to Linux, Solaris, and Windows. I’ve learned that C++ is really quite portable and there are just a few guidelines that you should keep in mind.



C++ Question of the Day: std::map index operator

Jon asks:



GCC 4.4.0 Released

GCC 4.4.0 was released on April 21st. Notable changes include fascinating new optimizations for loops. Particularly, they include the ability for the compiler to automatically rewrite loops to take into account memory layout of the system. I recall distinctly in my Intro to Data Structures CS class the teacher using the example of a two dimensional loop which iterated the “wrong way” (causing many disparate memory look ups and cache-misses) as a classic performance killer. Example (from GCC’s website), GCC is now able to perform the following optimization:



When to use class vs. typename in a Template Declaration

When declaring a template you can choose either “class” or “typename” for a template parameter. Example:



Project Euler - Problem 1 - Sum All Integers Below 1000 and Divisible By 3 or 5

The first Project Euler problem is to calculate the sum of all integers below 1000 which are divisible by either 3 or 5. My solution is implemented entirely in C++ templates. The value is recursively calculated at compile time. The template specialization struct Problem1<0> stops the recursion and returns 0. To compile this code with gcc you must expand the maximum allowed template recursion depth to at least 1000. ` g++ EulerProblem1.cpp -ftemplate-depth-1000`



Building Visual Studio Express Projects From the Command Line

If you search around for how to build Visual Studio projects from the command line you will find references to the DevEnv executable. When working with Visual C++ Express, however, that tool does not exist.



Getting the List of Default #define's From GCC

Most of the postings I make to this website are for my own personal reference. They are things that I want to make sure I don’t forget, or at least have easy access to. Today is no exception. For some reason, I can never remember the following command and have to track it down every time I’m interested.



When to use reinterpret_cast<> vs. static_cast<>

The boost developers mailing list recently discussed the differences between reinterpret_cast<> and static_cast<> C++ casting operators.



When to use #include "" verses #include <>

Different compilers treat the two types of includes:



Create a WMI Application - Refined

I recently had the need to be able to query the WMI via WQL (which are very fascinating and helpful technologies, actually) from C++. WQL essentially provides an SQL interface for querying system properties of a running computer.



Simple C++ String Conversions

The boost::lexical_cast<> utility is a handy way of converting objects to and from strings, providing a mechanism that many scripting languages have built in. lexical_cast works with any C++ type that has ostream and istream operators defined for it, that is, any object that cout << object; or cin >> object; would work with. This boost facility also does intelligent things such as throwing a bad_cast exception if the operation causes an error flag on the stream to be set. I use boost::lexical_cast<> throughout my code at work for things like serialization of objects for human readable communications. It is also sprinkled liberally throughout my code for handling things like quick debug logging:



Templated Constructors in C++: Using the "explicit" Keyword

Sometimes, in the course of C++ template based programming it might be desirable to have a constructor that is templated, like the following contrived exampled:



Prefer .at() to [ ] When Accessing C++ Vectors

I’m sure I will get some dissenting views posted in comments regarding this, but I just came to this conclusion while trying to track down a memory bug in the past few days. First of all, what’s the difference? Take the follow code to set up our scenario:



Overloading && and || Operators in C++

Short answer: don’t do it! Long answer: As the C++ example from the article on Real World Haskell Chapter 1-2 showed:



Haskell Pattern Matching and Network CIDR's

I was recently faced with the following code which is simple but provided the perfect example to practice some Haskell.



Real World Haskell: Chapter 3

Chapter 3 of Real World Haskell is “Defining Types, Streamlining Functions.”



Real World Haskell: Chapters 1-2

Chapter 1 of Real World Haskell covers the most basic aspects of the language, such as common operators and operator precedence and gives some overviews of aspects of the language.



Nobody Understands C++: Part 7: C++ Coding Standards

In case you find yourself asking where I get the stuff from that I blog about and wondering if I’m just making stuff up; many of the “Nobody Understands C++” articles on this website are inspired by principles found in the book “C++ Coding Standards” by Herb Sutter and Andrei Alexandrescu.



Nobody Understands C++: Part 6: Are You Still Using Pointers?

It is best to avoid using pointers in C++ as much as possible. The use of pointers can lead to confusion of ownership which can directly or indirectly lead to memory leaks. Even if object ownership is well managed simple (and difficult to find) bugs can also lead to memory leaks.



Cruel and Unusual C++ Interview Questions

I do not, contrary to the opinions of some (rather weepy) individuals, ask interview questions like, “name the types of C++ inheritance” then flog the interviewee for saying “virtual, non-virtual, single, multiple,” because I was expecting “public, private, protected.” Indeed, it’s been more than two years since I last had the opportunity to interview, but when I did, I made sure of two things:



Swig Starter Kit 0.0.2

Release 0.0.2 of Swig Starter Kit was just released. This release sees the addition of template usage examples, including custom function templates and STL usage. Using a SWIG template declaration we are able to instantiate a specific template and use it from our script code.



Swig Starter Kit 0.0.1

I just put up the first release of a new project, Swig Starter Kit, on google code.



Why is ++i faster than i++ in C++?

I’ve heard this question come up a few times in C++ programming circles, “Why is ++i faster/better than i++?”



C++ Loop Optimization: Part 3: Dynamic List Generation

I felt like this topic deserved one more article. (See part 1 and part 2 for the background.)



C++ Loop Optimization: Part 2

After the first article on loop optimization my cousin pointed out to me that in some cases, tail recursion can actually be faster then loops in C with the help of tail recursion elimination.



C++ Loop Optimization

I recently had a friend point out to me that your typical loop seen in every day code has minor inefficiencies in it which can add up to a good amount of time being wasted. I agreed with him, so I set out to write an article on how to optimize your C++ loops.



Are You Working Too Hard as A C++ Developer?

There is probably a multitude of ways that you can work too hard as a C++ developer, but there are two specific ones that I would like to focus on:



Crossplatform C++: Part 1: Intro

This is the first in a series of articles on writing crossplatform applications with C++. These articles will be based on the premise that strict adherence to standard C++ will result in extremely portable code which will run on almost every platform available, including embedded systems. However, limiting yourself to strict C++ also means limiting yourself to the standard C++ libraries, which only cover basic file and console input and output. That means no graphical user interfaces. This is certainly a limitation we will address. We will progressively add in more and diverse libraries which will slowly limit the full range of platforms we can run on.



Pass By Iterator

Pass by iterator is not a new concept, but one that we are going to perhaps give a new name to today and propose as a standard for normal usage. If you take for example the normal way of passing around standard containers:



Top 5 Myths About C++

We’ve now completed 5 articles in the “Nobody Understands C++” series so here we are going to recap the misconceptions we have covered.



Nobody Understands C++: Part 5: Template Code Bloat

On occasion you will read or hear someone talking about C++ templates causing code bloat. I was thinking about it the other day and thought to myself, “self, if the code does exactly the same thing then the compiled code cannot really be any bigger, can it?” Here are the test cases presented, first without the use of templates, second with the use of templates. Exactly the same functionality and exactly the same code output:



Nobody Understands C++: Part 4: Functional Programming

Standard Algorithms Few C++ developers seem to appreciate that the standard C++ library is actually designed around functional programming principles.



Multithreaded C++: Part 4: Futures and Other Thread Handlers

We’ve covered the “Assembly Language”, “C” and “C++” of the C++ threading world, and now we are going to try and move beyond that.



Thread Safety Locking Strategies

I’m going to cover a thread safety strategy I have been thinking about lately. Let’s look at an example for a typical “lock the variables as you use them” approach:



C++ Mutiple Dispatch!

In my last posting about C++ Multiple Dispatch I wondered if it was really any different than function overloading. I now appreciate that it is something that needs to occur at runtime, not compile time.



C++ Multiple Dispatch?

I clearly must be missing something. I just noticed this article on the O’Reilly ONLamp blog, discussing multiple dispatch in Perl. The example code given:



Nobody Understands C++: Part 3: Templates

C++ templates is a huge topic that we will not fully cover here. While we have covered templates in the past, this article will cover the very basics and the reasons why we would want to use templates.



Multithreaded C++: Part 3: RAII And Threads

If boost::threads represent the C of multithreaded programming, then RAII and automatically managed threads represent the C++ of multithreaded programming. In the last article we promised that using more RAII would allow us to get this code even smaller and better to manage. Here is the result of that:



C++ Templates: Euclid's Algorithm

A while back I was going though the first chapters of Knuth’s The Art of Computer Programming and came across Euclid’s algorithm for finding the greatest common denominator. I decided to implement the algorithm as a C++ template. Here’s the complete example.



Multithreaded C++: Part 2: Boost Threads

Note 2016-03-15 std::threads now have all this and more



Nobody Understands C++: Part 2: RAII

Understanding RAII is critical to understanding good C++ design.



Multithreaded C++: Part 1: Pthreads

Note that some of the details on volatile are out of date now - 2016-03-15



C++ Question of the Day: Volatile Keyword

Jon asks:



C++ Templates: Using Templates to Generate the Fibonacci Sequence

The follow code demonstrates a method for generating the Fibonacci Sequence at compile time. Since the sequence is generated at compile time runtime execution of retrieving a number is constant time.



Nobody Understands C++: Intro

This is going to be the first post of several, though I’m not sure how many just yet. The title of the post should be self explanatory, but I will elaborate. It is my strongly held belief that C++ is generally poorly understood and gets a bad rap because of this. It is also my belief that this is NOT the fault of C++, but rather the fault of old-school C++ developers who learned the language before the language was ratified in 1998.



Boost Preprocessor Metaprogramming and Intro to Templates Revisited

Say you come up with a clever idea for initializing standard container types (blatantly stolen from the C++0x Initializer List concept). It might looks something like the implementation below:



Boost::Spirit: A BNF Parser Generator

The boost spirit library allows for direct translation of a BNF grammar into C++ code which generates a parser at compile time. The following example, from http://spirit.sourceforge.net/distrib/spirit_1_8_3/libs/spirit/doc/introduction.html truly does this concept more justice than I could: BNF Example:



Copying a File in C++, The Easy Way

Just a few days ago I spent way too long looking at the boost libraries to see if there was a way of adapting a std::fstream to an iterator type. I didn’t find what I was looking for and did what I wanted a completely different way.



Automatically Generating Templates with the Boost Preprocessor Metaprogramming Library

boost contains a preprocessor metaprogramming libary. What this means, simply, is that it is possible to write code which generates code. The full docs are here.



Templates in the Real World

Let’s say I’m doing some cryptography work. I’ve just received a signed message from another machine and I want to validate the signature. I have a few options:



Blogging the C++ Language: Cast Operators

Today I will be covering all 4 of the C++ cast operators.



C++ Inheritance Access Specifiers (previously: Types of C++ Inheritance)

In an effort to reduce the number of nonconstructive comments posted by visitors who do not read the entire article or previous comments, I have decided to change the title of the article and the initial summary to something more accurate.



Milestone 3.7 Released

Milestone 3.7 was released on Sourceforge today. This release adds the ability to build a Perl extension for using the Crate Game Engine library from within Perl.



Milestone 3.6 Released

Milestone 3.6 of the Crate Game Engine was release to sourceforge today. This release adds support for generating a Swig based wrapper extension to the library for use with Python.



Swig Wrapper Working

Today I got the Python SWIG wrapper working.



Game Loading

Last night I proved the expat is going to work for me by getting game object models loading. Still missing a few pieces, like loading of actions and connections from the .xml file. I expect in the next day or few to have game loading fully working and be able to release a new version. This time I will also release a windows build to go with it.



How To Build a wxMozilla Based App in Cygwin/MinGW

What follows is a posting that I made to the wxMozilla-devel mailing list. I promised viewers of this site that I would post info on how to build biblestudy under Cygwin/MinGW, so here it is, please post comments if you have any questions.



Expat

Well, noone responded to my last blog, so I went ahead and decided to use the expat library. I’ve encapsulated the function of loading an xml file into a “WorldLoader” class. None of this is checked in, but in the next day or two I expect to be able to load a world from an xml file and maybe I can get some other people involved in making games for the fledgling engine.