Bryninatored at Svetjana’s

Had a great, if not slightly drunken, time at Svetjana’s birthday drinks the other night. There was copious amounts of food, and some more of Meg’s friends for me to meet which was nice. In that order 😉

Superstar

There was also a little game called Singstar, which is freakin awesome. If you haven’t played it you’re not living.

Said game is never far from it’s owner, the unstoppable .. the Superstar .. the mechanical voicebox .. the Bryninator.

Bryn

The man’s no slouch, he didn’t rack up those 8520 points singing “Mary had a Little Lamb” but rather INXS’ “Never tear us apart” .. he’s not to be messed with.

Posted by mike on Thursday July 20th, 2006, tagged with , | comments disabled

Not compiling your code snippets considered harmful

Paul Wayper takes issue with the habbit kernel programmers have of #defining things as do { stuff; } while (0).

He points out that this can lead to:

if (x > y)
    exch(x,y);
    call_foobar(x,y);
else
    x = 0;

And says:

.. the exch() call completes the if statement and the call_foobar() call is executed unconditionally. Indenting in this case is worse than a sham, it actively deceives the programmer into thinking that the logic will work when it won’t.

Although I agree with his point, that mixing #defines that contain { } and if/else blocks that don’t can be dangerous, the example doesn’t actually compile. To trigger the bug you need:

if (x > y)
    exch(x, y);
    if (x)
        printf("hello!");
else
    x = 0;

Which after expansion of the macro looks logically like:

if (x > y) {
    .. guts of exch ..
}

if (x)
    printf("hello!");
else
    x = 0;

So it’s still nasty, but in the trivial if/else case you are safe.

Don’t miss some more of Paul’s excellent work.

Posted by mike on Thursday July 20th, 2006, tagged with , | comments disabled