C++0x: The Dawning of a New Standard


 
The DevX site has some great articles about the impending update to the C++ Standard, likely to issue in draft form later this year. From a game developer standpoint, the feature that is most exciting is rvalue references, which has the promise to change what today are copy operations into "perfect forwarding" operations. This will drastically improve the speed of STL containers, for instance. You can read what Bjarne has to say about about rvalue references here.
Advertisements
Posted in C++ | Leave a comment

Gamefest 2008 Preview


 
Gamefest 2008 (Seattle edition) is only a few days away: July 22-23. Gamefest comes to London on August 6th, and to Tokyo on September 4th.
 
Expect some exciting announcements from the keynote on Tuesday morning, July 22nd.
 
Some new/enhanced things this year:
 
  • The conference has expanded from one to two floors at the Seattle Convention Center.
  • Many Microsoft game technology teams will have booths at the expo; this is a unique opportunity to meet directly with the folks creating technology you rely upon.
  • There are some "virtual" tracks this year, collections of talks that span the normal tracks. For instance, there’s a virtual track for some of the exciting new features that we announced at E3.

Hope to see you there!

Posted in Game Programming | Leave a comment

My Favorite C++ Feature


 
What’s your favorite C++ feature? There are many to choose from. Encapsulation and polymorphism. Library features like iterators and algorithms. Templates and generic programming.
 
My favorite feature: destructors.
 
Destructors and C++ go together like peanut butter and jelly. I do my best work in destructors. So does much of the standard C++ library. Think about it for a moment. Our friend stl::vector would be a very poor container without a destructor. And tr1::shared_ptr would not be much use at all.
 
When I review code, I often find that the addition of a class or two with the right destructors can turn unreadable code into sublime code.
 
Here’s food for thought: the proper use of destructors and owned pointers (using shared_ptr or something similar) can eliminate resource leaks completely. A worthy goal indeed.
 
Posted in C++ | Leave a comment

Fine Gems


 
An exciting new package arrived on my doorstep this week: a copy of Best of Game Programming Gems, edited by my friend Mark DeLoura. I’ve contributed many gems to this series over the years, and I edited the networking and multiplayer section in Game Programming Gems 4. The new Best Of volume includes four of my gems. Mark did a good job on choosing the best ones:
 
  • Custom STL Allocators
  • Utilizing Multicore Processors with OpenMP
  • Secure Sockets
  • Bit Packing: A Network Compression Technique
There are dozens of other great gems covering math, physics, AI, graphics, networking and audio. Check it out!
 
Posted in Game Programming | Leave a comment

Const input parameters and typedefs


 
In good API design, one specifies unchangeable data that’s passed by pointer as const:
 
   void foo( const Stuff* pConstantStuff );
 
The compiler will guarantee that the "Stuff" pointed to by pConstantStuff is not modified by foo(). This is goodness. Microsoft APIs have a habit of using typedefs for structures, ala:
 
   void foo( const STUFF* pConstantStuff );
 
In fact, some people even use typedefs for pointers to structures:
 
   typedef Stuff* PSTUFF;
 
And they write the API like this:
 
   void foo( const PSTUFF pConstantStuff ); // Evil; this does not do what you expect!
 
That last version is not code you ever want to write! What it seems to promise is not what it actually promises. The compiler interprets it as:
 
   void foo( Stuff* const pConstantStuff ); // weird but technically correct
 
This version guarantees that the pointer itself cannot be changed by the function. However, the contents of pConstantStuff are no longer constant. The code can change the contents and the compiler will happily oblige! There are two solutions. Solution one is to create a const version of the typedef and use it where appropriate. Here’s how winnt.h does it for strings:
 
   typedef char *LPSTR;
   typedef const char* LPCSTR;
 
The preferable solution is to avoid typedefs for pointer types and use const directly whenever you need it. Use const whenever you possibly can. In return, you get readable code that clearly expresses the intent — and the compiler properly enforces the intent.
 
Posted in C++ | 1 Comment

BoostCon 2008


 
I spent the week of May 5-9 in Aspen, Colorado attending BoostCon. BoostCon is all about Boost, a collection of free portable C++ source code libraries.
 
This is the second year of the conference. There were about 80 attendees, including C++ luminaries, Standards Committee members, Boost library authors and Boost library power users. The reason I attended is because the conference includes discussions on hardcore C++ usage plus future language and library features. Many of the Boost libraries (there are about 80) are already in the draft of the next version of the C++ Standard, and much of the work that happens in Boost libraries leads to new language features and new library components. Being at BoostCon is a bit like travelling to the future of C++.
 
Conference Takeaways
  • C++0x (the next version of the C++ Standard) takes big steps toward improving the efficiency of code — a big win for game developers.
  • C++0x has a lot of new features. Most of the new features are not language features, but new standard libraries. Most of the language features are designed for library writers.
  • You can find the current working draft of C++0X (May 2008) at http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2008/n2606.pdf. Lots of goodness to sink your teeth into.
  • Concepts, one of the most significant potential language features, is not in the draft. However, it is still being considered for inclusion.
  • Borland has re-energized its C++ effort and is working on a C++0x compiler.
  • Meta languages continue to be a surprising mini-topic. Observed C++ meta-languages from this year included:
    • template metaprogramming (of course)
    • boost::format language
    • regex regular expression language
    • boost::spirit simple grammar parser
    • boost::parameter function definitions

Here’s one of my favorite new features of C++0x. I hate writing code like this:

for( std::vector<Stuff>::iterator i = v.begin(); i != v.end(); ++i ) // C++ today

Wouldn’t it be nice if the compiler just knew what i was. It has to be the return type of v.begin(), right? C++0x allows you to avoid all that crazy typing:

for( auto i = v.begin(); i != v.end(); ++i ) // C++ in the future

That gives you a tantalizing glimpse of one of the many new features we have to look forward to in C++.

Posted in C++ | 1 Comment

Gamefest 2008 is Coming


 
Put it on your calendar: July 22-23 in Seattle. Gamefest is coming! If you’ve been to Gamefest in the past, you already know it’s the ultimate place to get the latest and greatest information on creating games for Microsoft platforms like Xbox 360 and Windows Vista. If you work on games and you haven’t been to Gamefest, you’re missing something really special. I’ve already seen some of the proposed talk abstracts, and you can expect some amazing content from excellent speakers.
 
Posted in Game Programming | 1 Comment