‘c++’ Archive

Don’t try for exception safety Thursday 20th December 2007 3 Comments

Achieve it! “Do or do not, there is no try” – Yoda, on strong exception safety. I’ve decided that I like exceptions a lot more now that I know how to use them to my advantage. Take the following piece of code: #include <cstring> using std::memcmp; size_t DoConversion( char* dst, size_t dst_len, const char* src, […]

extern arrays and pointers Saturday 17th November 2007 Comments Off on extern arrays and pointers

Quick, what’s the difference! extern char data[]; extern char *data; Well the first one’s and array and the second one is a pointer. You can treat them in the same way, but they are completely different things. Here’s a function which looks the same with both declarations of data: char f(int a) { return data[a]; […]

A mini test framework in a single header file Wednesday 31st October 2007 2 Comments

After trying it on a number of projects, I’m now very enthusiastic about test driven development. At home I’ve rather missed the minimal support code that I had at my old job, so I’ve rewritten a miniature test framework in a single header file. Only this time, it’s better. Framework implies something rather big. This […]

Address Space Monitor vs Google Sunday 28th October 2007 1 Comment

In an unusual coincidence, googlebot visited my homepage the day after I put the link to Address Space Monitor live, and the next day it was the top search result for the query: ‘Address Space Monitor’. It stayed there for a few days but now the asm homepage is not in Google’s index at all. […]

Address Space Monitor Tuesday 23rd October 2007 Comments Off on Address Space Monitor

Finally, I manage to release software on the unsuspecting world! I wrote this tool in response to spending some painful time debugging a process which seemed unable to allocate a chunk of memory when most conventional tools were showing that the process wasn’t at the limit in terms of memory usage and the system hadn’t […]

Template Metaprogramming Errors Friday 14th September 2007 Comments Off on Template Metaprogramming Errors

I’ve been having a very limited play with template metaprogramming and at one point I managed to end up with what appeared to be an infinitely recurring error message. It turns out that it wasn’t, as I was able to redirect all of the stderr output from the compiler to a file. It was, however, […]

More obscure places to find the template keyword Thursday 26th July 2007 Comments Off on More obscure places to find the template keyword

Consider the following ill-formed c++ code: class A { public: template< class U > U f(); }; template< class T , class U > class B { public: T g() { // error: expected primary-expression before ‘>’ token return u.f< T >(); } private: U u; }; template<> int A::f<int>() { return 0; } int […]

Cross-compiling gcc, glibc and all that. (Part II – the script) Wednesday 18th July 2007 Comments Off on Cross-compiling gcc, glibc and all that. (Part II – the script)

crosscomp.sh So here it is, the script that does it all. Although it is a shell script, I thorougly recommend not running it, but cutting and pasting it, section by section, into a terminal session so that you can fix up any environmental issues that cause it to fall over. There are some paths at […]

Cross-compiling gcc, glibc and all that. Monday 16th July 2007 Comments Off on Cross-compiling gcc, glibc and all that.

Yippee! I finally managed to get a working cross-compiler x86 -> x86_64 on one of my linux boxes setup with c++ and shared library support. gcc, the kernel and glibc have the most annoying set of interdependencies so doing a ground up build is horribly painful, consisting of several rounds of bootstrapping. Like most people […]

Building code (Part II) – dependency generation Wednesday 27th June 2007 Comments Off on Building code (Part II) – dependency generation

Automatic dependency generation can make a huge difference on productivity. If you have a large project then building every source file, every time in a code and fix cycle can grind the process to a halt. Likewise, if your build process doesn’t rebuild any object file that already exists, or only rebuilds it when the […]