caustik's blog

programming and music

Archive for the ‘Funny’ Category

Bunnie is MonGyver

with 6 comments

Just got back from some travel with bunnie, adrian and hb+pana. To chronicle our goofy adventures, adrian put together a DivX video. The video is called “Mongyver” (spoofing Macgyver, the best TV show ever created), and bunnie is the main character.

We came up with the idea when bunnie started fixing a broken sound card on my laptop using a lighter and aluminum foil. Bunnie is the Mongolian Macgyver :)

I do all my own stunts! (see the lawn chair scene).

stunt

You can watch the video online, or download it (right click, Save As).

Written by caustik

September 25th, 2006 at 5:51 am

Posted in Funny,Travel

Tagged with , ,

Ridiculous C-code

with 2 comments

For no particular reason I decided to write the following confusing line of C code today…

const _=0;do;while(0?0,1:!_,_);

Might make an interesting interview question. Can you parse it in your head?

Here are some reasons why this seems very confusing:

  1. const _=0;This is not much different than “const int a = 0;”… It is just using the implied “int” type, and rudely using the single underscore character, which is acceptable (but taboo) as a variable name.
  2. do;whileThis looks odd, but is actually valid. Typically, people implement a do/while as “do{}while(…);” – however, it is equally valid to replace the {}’s with a single statement, even an empty do-nothing statement (“;”).
  3. a?b:cI am tempted to fail somebody in an interview immediately if they have no clue what this operator does. It isn’t that it’s particularly critical or anything -but if you’re a C coder and you’ve been around the block – it would be very odd for you to not be familiar with the conditional operator. Still, it is rare enough to be difficult to brain-parse.All this does is evaluate “a”, and if the result is true, evaluates “b”. If the result if false, it evaluates “c”. Simple.
  4. !_,_ Okay so this one is nasty. I might not expect everybody to be familiar with this guy. What happens here is the variable “_” is being evaluated as negated, then the variable “_” itself is being evaluated. The trick is, only the right side of the comma is actually used as the value of the expression. Huh?

    This is primarily useful in things like a “for” loop. Since the general syntax of a for loop is “for(a;b;c)”, you at first may feel a little limited. How can I increment two variables on each step? Easy. “for(a;b;d++,e++)” – note the comma operator allows you to squeeze two subexpressions into “c”. In this case, nobody knows or cares that the expression value is, in the end, defined only by e++. The result is not being used at all.

    I’d be interested to hear some real world valueable uses for the comma operator, aside from a “for” loop.

Written by caustik

August 17th, 2006 at 8:25 am

Posted in Funny,Programming

Tagged with ,