Olly Betts: Empty Strings in C++
Gaurav (one of Xapian's GSoC students this year) queried my advice that it's
better not to explicitly initialise a std::string in C++ like this:
std::string s = "";but instead to write:
std::string s;It could be argued that the former makes it clearer that the string is initialised (since C++ does inherit C's behaviour of not implicitly initialising variables of fundamental types, such as int and double). But objects aren't left uninitialised - the default constructor gets called (or if there isn't one, the code won't compile). The downside is that you get quite a lot more code from the first version than the second. Perhaps compilers will grow smarter and in future both the above will compile to the same code, but that's not true today. Here's a simple bit of test code:
#include <string>
std::string f()
#ifdef EXPLICIT_INIT
std::string s = "";
#else
std::string s;
#endif
return s;
And I'll compile it with GCC (g++ (Debian 4.7.2-4) 4.7.2) on x86-64 to produce
assembler output:
$ g++ -O2 -S s.cc -o s1.s $ g++ -DEXPLICIT_INIT -O2 -S s.cc -o s2.s $ diff s1.s s2.s 1a2,4 > .section .rodata.str1.1,"aMS",@progbits,1 > .LC0: > .string "" 9,10c12,25 < movq %rdi, %rax < movq $_ZNSs4_Rep20_S_empty_rep_storageE+24, (%rdi) --- > pushq %rbx > .cfi_def_cfa_offset 16 > .cfi_offset 3, -16 > movl $.LC0, %esi > movq %rdi, %rbx > subq $16, %rsp > .cfi_def_cfa_offset 32 > leaq 15(%rsp), %rdx > call _ZNSsC1EPKcRKSaIcE > addq $16, %rsp > .cfi_def_cfa_offset 16 > movq %rbx, %rax > popq %rbx > .cfi_def_cfa_offset 8(As an aside, I wouldn't recommend spending a lot of time digging into the assembler your compiler produces, but if there's more than one equivalent way to write code for a common case (as here) and you want to know which is most efficient, it can be informative to see what code is produced for each). You don't really need to know x86-64 assembler to grasp what's happening above, which is lucky, since I don't really know x86-64 assembler. In the first hunk, we get an empty literal string being added to the rodata (read-only data) section; and in the second, instead of two instructions which copy a standard empty string representation, we get much more elaborate code, including a function call to _ZNSsC1EPKcRKSaIcE - the C++ mangled name for the std::string from const char * constructor:
$ c++filt _ZNSsC1EPKcRKSaIcE std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)I also tested the example above with clang (Debian clang version 3.0-6 (tags/RELEASE_30/final) (based on LLVM 3.0)) and the resultant code is fairly similar for each case. The overhead for doing this once isn't going to matter, but if it happens every time you declare a std::string variable, the cumulative effects may be measurable. And as well as taking longer to execute, the larger code will cause greater CPU cache pressure.


It's been a few years coming, but the day has finally arrived.
Contrary to some rumours which I've had to debunk over the years, the
m68k port did not go into limbo because it was kicked out of the
archive; instead, it did because recent versions of glibc
require support for
While I'm happy and, in fact, a bit proud about that fact, there are
still a few minor issues that make the whole process a bit less smooth
than it could be:
Given the very positive feedback for Dennis Felsing s tool
I wanted to be able to use the GMail web interface on my work machine, but for 





A long time ago, I spent many many hours playing Frontier (Elite 2) on
the family Atari ST. It was nice-looking (oh, those sunrises on
distant planets!), playable, varied, had ample room for progression,
very different possible roles, a huge universe of which nobody could
ever hope of exploring more than a tiny fraction, and it was basically
the first game I encountered with no set goals. You are a spaceship
pilot in a galaxy colonised left and right, and it's up to you to
decide what you want the game to be. Pirate, headhunter, mercenary,
trader, taxi, explorer, there's no end goal to achieve except what you
fix for yourself. That was, for me as a youngster, a mind-opening
experience, which I never felt as strongly since (with the possible
exception of the Creatures game, but I barely tried it).
Then came modernity, the PC, and the First Encounters sequel
(Elite 3). It added moderate complexity to the gameplay, some sort of
political evolution among the factions and a kind of plot so the
galaxy was no longer quite so static, but the end results were still a
bit disappointing. It felt like Frontier with a few
not-exactly-overwhelming textures stuck onto the ships, a loose plot
arc, and a third faction, the Alliance of Independent Systems, beyond
the Federation and the Empire. Not that exciting, although the name
of the Alliance's capital star system stayed in my mind.
So, like many others, I came to wait for Elite 4. That wait started
in 1995, more than seventeen years ago. During that time, Duke Nukem
Forever was announced, promised, developed, postponed, abandoned,
found again, developed again, and it was even actually released in
2011, while Elite 4 went into the same kind of hell only without the
actual release (yet).
At some point I started trying various substitutes to help pass time.
There was Parsec which was a nice-looking space combat simulator,
multiplayer and all, but never felt like finished. Development slowed
down to a thin trickle, and it seems like it only recently started
again as 