February 04, 2014

Setting really default browser

When Chrome or Chromium spontaneously becomes your default browser and all normal ways in GUI say that it isn't, then run:

sudo update-alternatives --config x-www-browser

and select whatever you want, e.g.:

There are 2 choices for the alternative x-www-browser (providing /usr/bin/x-www-browser).

  Selection    Path                       Priority   Status
------------------------------------------------------------
* 0            /usr/bin/chromium-browser   40        auto mode
  1            /usr/bin/chromium-browser   40        manual mode
  2            /usr/bin/firefox            40        manual mode

So many ways to do one thing... why?

February 01, 2014

Funny thing with arrays in C

It's a funny thing that C does not really have arrays. It has something that looks like an array but is really a pointer to a memory location. There is an array indexing expression, array[index], that is just shortcut for the expression (*(array + index)). Therefore it’s equally valid to write index[array], which is also shortcut for (*(array+index)). Just a pure commutative operation. Powurrrful way to shoot yourself in a leg.

So, look at this piece of code:

#include <stdio.h>

int main(int argc, char const** argv)
{
    char* str = "test";

    printf("%c\n", 0[str]);
    printf("%c\n", *(str+1));
    printf("%c\n", *(2+str));
    printf("%c\n", str[3]);

    return 0;
}

Do you think this will blow up? Heh, no way! Watch this out.