Reporting compiler bugs

Once in a life-time, you run into a compiler bug … well, that used to be the case, before HLSL/GLSL/OpenCL/CUDA/C++0x whatever started to crop up and require new front and especially code generation back-ends. More often than not, people just accept that there is a bug somewhere and try to work around it, but you should always remember to report it so it can get fixed quickly. In this post, we’ll take a look how to efficiently report bugs in compilers, as it usually requires quite some work to make an useful bug report. Continue reading

Posted in Programming | Tagged , , | 2 Comments

New blog style

I’m working a new blog style. Please report any problems you encounter!

Blog with old style (used until June 2010)Right now, there are some issues with Opera and Chrome, while Firefox 3.6 works correctly. For the best viewing experience, please try Firefox for the time being while I iron out the issues with Chrome/Opera. [Update]I think I’ve fixed the issues with Chrome.[/Update]

Blog with new style from June 2010

The theme uses CSS3 for all shadows (specifically, text-shadow and box-shadow is used.) This keeps the load time pretty low and still provides some very nice effects. The menu uses the :last-child selector, and thus does not work with Internet Explorers before IE9. Overall, it’s a pretty tiny theme, as I finally got round to create it as a child theme instead of rebuilding most from scratch. The parent theme used here is twentyten (WordPress 3.0 default.)

Posted in General | Tagged , | Leave a comment

Disk failure (with some data loss)

My primary disk just failed yesterday evening (around 21:30), so I lost at least all data from this week (last backup is from Sunday, 19:00.) However, I think I didn’t miss any unread e-mails, but of course I cannot check as all mails from this week are definitely lost. In case there was something urgent, please send me a mail again.

I ordered a new hard disk which should arrive early next week. I hope to be back up (no pun intended) & running around Thursday again. As soon as the RMA for the faulty disk finishes, I’ll plug it in for daily backups. While I’m at this: What’s your backup strategy?

Here I have one additional internal HDD which I use for backups once a week. I don’t have a “disaster” backup yet at a secondary location; I wonder how well Amazon S3 would be suited for something like this (or SkyDrive.) I’m also planning to install a NAS in my home network and use this for backups, but I haven’t found a nice and free backup software yet. Second problem with the NAS is how to backup the NAS, in case of failure (RAID-5 might be a solution, but how to guarantee that I can rebuild the RAID-5 in 4 years, or, worse, in case the controller fails and can’t be replaced?) I’m curious to hear what backup strategies you employ, and how you coped with disk failures so far.

Posted in General | Tagged , | 4 Comments

Avoid unsigned types by default

For some reason or another, unsigned types in C++ are heavily overused. I know that Java doesn’t have them, and many students who learn programming with Java think this is a really serious deficiency which they have to make up by using unsigned types everywhere … however, it turns out, that you will rarely need unsigned types, and in most cases, they do more harm than good.

First of all, there are some cases where you need unsigned types. Pretty much all of these cases can be grouped into two categories:

  • Interop: Someone somewhere expects an unsigned value, so you have to convert your stuff at some point. You should try to convert it as late as possible, but with some sanity check. For instance, if you call an API which expects an unsigned size, and you have a signed size in your application, convert only after sanity-checking your signed value!
  • I/O: Disk or network I/O often requires the use of unsigned data types, as you typically want to work on the raw bit pattern of the value and not on the actual value. In this case, unsigned types fit and should be used.

Everywhere else, you should really try hard to avoid them. Especially when you design an API, stay away from unsigned types. There’s a very good article by Scott Meyers on this topic which explains the problems with unsigned types and interfaces. The main problem is that an unsigned type makes error/sanity checking impossible. If you have a function like memset(void* t, size_t size) and a pod like

struct pod {
    unsigned char flags;
    Vector3 coords;
};

and you pass on something like memset(&pod, sizeof (pod) - sizeof (Vector4)); because you vaguely remembered that pod has a Vector4 and a flags field in it, you’re going to clear around 18446744073709551613 bytes worth of data if running on a 64-bit system — with signed types, a quick assert(size >= 0); would have failed with size == -3.

This happens far more often than you would expect. Since I’m trying to use signed types as much as possible, I’ve found lots of lots of places where I can sanity-check values using asserts and pre-condition checks than before. Even for typical use cases like I/O routines (fwrite) or memory stuff (malloc), you can get away with one less bit in practically every case — I don’t remember ever having seen a call which would allocate or write more than 231 elements on a 32-bit machine; let alone 263 elements on a 64-bit machine. So, next time before you start typing unsigned type size, think twice if you’re really ever going to need that extra bit, or whether you are willing to trade it off for error checking.

Note: This does not imply that you don’t have to think about valid value ranges. The only help you get from signed types is that overflows are much harder to exploit if you sanitize most values in between. You should however still use things like SafeInt to make sure your arithmetic stays in range.

Posted in Programming | Tagged , | 12 Comments