Reading Berkeley's FM

Post by Nico Brailovsky @ 2010-03-26 | Permalink | Leave a comment

I got this from Oracle Berkely DB's FM:

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

Take a good look at that pice of code:

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

Again:

  a_number = sizeof(Whatever)->field;

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

  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.


In reply to this post, Nicolás Brailovsky » Blog Archive » Operator sizeof (AKA Reading Berkeley’s FM, take II) commented @ 2010-03-29T11:57:18.000+02:00:

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

Original published here.