Wednesday, September 22, 2010

Really silly error

This morning, I found a really silly error in my simulator. It's part of a bug that I've been after for a long time. Finally, I think I've squashed that bug which has been causing random core dumps.

It turns out that in a collection of integers, when swapping two numbers, say a and b, I was doing the following:

temp = a;
a = b;
b = a;

Instead of the blatantly obvious:

temp = a;
a = b;
b = temp;

It is utterly unbelievable how such an error could have slipped my attention. Oh, well, us MVPs are also mere mortals after all.

1 comment:

basit said...

if you don't want to use any temporaries.

a = a ^ b;
b = b ^ a;
a = a ^ b;

- basit