Hack of the day: C++ compile time assertions
A very common problem in programming is to calculate prime numbers fast.
There are a lot of interesting ways to solve this problem. I want to show you some solutions without the need for a complex algorithm. This type of solutions can also be applied to a lot of problems that may occur during your daily work. » more
Hack of the day: Round up to the next power of two
January 19, 2011
Using right shifts, you can compute the next power of two of an 32-bit integer in a very effective way: » more
Hack of the day: Use messages in asserts
January 19, 2011
A programmer should often use assertions, so he is able to detect errors as soon as they occur.
In C++ the standard assert-macro doesn’t allow for an additional message. But with a simple workaround, you can print out additional information when the assertion occurs: » more
Hack of the day: Byte flipping
January 15, 2011
Sometimes it is required to flip the bytes of an integer. For example some image formats stores the chunks in ABGR format, so you have to flip them for use in OpenGL or Direct3D. » more
Hack of the day: Measure time in C++
January 13, 2011
I recently got asked how to measure time in C++ in milliseconds. Surprise, surprise: It’s very easy: » more
Hack of the day: Data structure padding
January 6, 2011
In C/C++ you can define structs for your data. Sometimes it could be a little bit confusing how much memory they’ll allocate, if you don’t know what’s happening behind the scene. » more
Hack of the day: Put URLs directly in C++ code
January 4, 2011
This is not really a hack, but it’s fun anyway. » more
Hack of the day: Alternating among two values
December 31, 2010
During game development you often need a variable that switches between two values with each call/loop/frame. » more
Hack of the day: c/c++ goes down “operator”
December 29, 2010
With the following for-loop you can decrement x until it reaches zero: » more