Nicolás Brailovsky


A modern blog

Reading Berkeley’s FM

author Posted by: nico on date Mar 26th, 2010 | filed Filed under: C++, Grumpy, Programming, WTF

I got this from Oracle Berkely DB’s FM:

  1.  skey->size = sizeof((struct student_record *)pdata->data)->last_name;

Take a good look at that pice of code:

  1.  a_number = sizeof((T*)pdata->data)->last_name;

Again:

  1.  a_number = sizeof(Whatever)->field;

Wait a minute. typeof(sizeof(x)) == const unsigned int. Right? So, again:

  1.  a_number = 42->field;

There’s no way that first line can compile. Go and check it (in the example, not the last line please). I’ll wait. Done? Yeap, I was surprised to, it does indeed compile. Mi first reaction towards this discovery went something like this:

What is going on there? It took me a while to figure out how evil Berkely ‘s manual can be. The answer next time.

tagOne Response to “Reading Berkeley’s FM”

  1. Nicolás Brailovsky » Blog Archive » Operator sizeof (AKA Reading Berkeley’s FM, take II) Said,

    [...] Last time I told you about an evil snipet I found on Oracle Berkeley DB’s manual: [...]

     Add A Comment

trackback Trackback URI | rsscomment Comments RSS