• mina86.com

  • Categories
  • Code
  • Contact
  • Null: The never-ending story

    I have already mentioned some problems with the null pointer but my recent discovery knocked my socks off.

    By now, it should come with no surprise to anyone that 0 in pointer context acts as a null pointer (no matter of its actual representation). Moreover, it takes only a tiny bit of experimenting to figure out that expressions like (int)0 do as well. The latter is in itself a bit of a pita but it is conforming to the C++ standard which says:

    Prime numbers less than 100

    The #1 programmer excuse for legitimately slacking off: ‘My code’s compiling.’
    XKCD #303

    Anyone working in a major company must have been hit by some ‘funny’ mail from a coworker that helps everyone gets through the day. No different at my office — at one point all engineers have been challenged to write the shortest code in C that prints all prime numbers (and only prime numbers) less than a hundred each on separate line.

    This is an interesting brain-teaser so posting it here so others may choose to think about it while their code’s compiling.

    Of course, a ‘C program’ needs not to be taken too seriously — depending on not too far fetched undefined behaviours of given implementation is all right (but please do not use system or exec family of calls; not that I can see how that would help).

    By the way, if you’re interested in how this challenge looks solved in Rust, I’ve described that as well.

    0 is ambiguous

    It has been a long time since my last entry, so inspired by Adriaan de Groot’s entry, I decided to write something about 0, NULL and upcoming nullptr.

    I will try to be informative and explain what the whole buzz is about and then give my opinion about nullptr. Let us first inspect how a null pointer can be donated in C and C++.

    NTP over HTTP

    Sitting in a dark office, after swearing for hours at ATI video cards I noticed time on my computer was incorrect. ‘No problem,’ I thought as I started typing ntpdate. That’s where it struck me that our beloved IT department had blocked most of the Internet. Checking the time on a watch or a mobile phone was not an option — I had neither — nor was looking at GKrellM on another PC — that’s lame.

    ‘I wish there was a NTP-over-HTTP protocol’ I sighed. And then I realised there was…

    tabbed, urxvt extension

    Some time ago, I’ve modified the tabbed rxvt-unicode extension adding a few useful features. Somehow upstream did not want it while people started modifying the extension even more and so tabbedex fork came to be. The code can be browsed on GitHub or cloned from git://github.com/mina86/urxvt-tabbedex.git

    tabbedex carries a lot of changes and it would be futile to try and list them all here especially as the list would likely become out of date soon. Because of that, I recommend taking a look at the source code, which has, at the very beginning, a comment with a list of changes made.

    Public git repository

    And finally, after doing some paper work, I’ve created a set of public git repositories with various stuff written by me. At the moment, the most interesting is probably a dot-files repository which contains my configuration files — hope someone’ll find it useful.

    Double-checked locking pattern

    Jakiś czas temu w pewnych okolicznościach poruszony został wzorzec double-checked locking singleton, który jak powszechnie wiadomo nie jest do końca poprawny. Wynikła z tego krótka dyskusja, której kompilację pozwolę sobie wkleić poniżej (gdyż nie jest ona ogólnie dostępna, a nie lubię, gdy informacje się marnują).

    ls-cmd.pl

    Something for real unix geeks: Script that makes well known ls command work in Irssi the way God intended, ie. displaying nick list (no slash required).

    Irssi AI

    Script implementing advanced AI algorithms answering yes-or-no questions on a channel. It can answer all questions or only those sent to us (that is prefixed with our nick).

    MPD now playing for Irssi

    Simple script writing title of currently played song in MPD. It has a unique feature of automatically replaying to informations send by other users.