Source Code Tales Tamás Szelei's coding blog

Introducing rpclib

The 361st commit in the rpclib repository marks the first public release of rpclib, the project I’ve been working for the last ~11 months (294 days, to be exact). What started off as “throw this together in a month and then move on to the next thing” became a crazy journey of perfectionism and “I’ll add this tiny feature before release because what would people think if it’s not there”. Breaking and reworking things just for the sake of it. That’s a great way to have a side project to work on, but not a great way to finish it.

I realized this about a month and a half ago and since then, I’ve been working towards a complete state that I can release. Right now I’m minutes away from pushing the button to upload the 1.0.0-preview1 release. I decided to create a preview before the actual release, because at this point feedback is pretty important.

Continue Reading...

Back to the lab again

After unexpectedly losing the contents of my VPS, I recovered the scraps of my blog from the Wayback machine. I deleted one post, which had a larger amount of screenshots that I had no desire to recreate (and the post wasn’t so good anyway).

Anyway, the blog is here again, hopefully Google forgives the downtime. I made sure to use the old links and put extra effort into having the old comments in place.

The blog now runs on Github pages and is based on Jekyll. You can find the source here.

Regarding my VPS service provider: let’s just say, I won’t be recommending that company to anyone, anytime soon.

Continue Reading...

cmake is not great, but it doesn’t matter

CMake, the language is not great. It is just not a pleasant tool to work with. Not at all; it feels like it was not designed as a language, but a mere configuration file that sets build options in a compiler-agnostic way. But, it hits many important bullet points for building software and most importantly: “just works”. As a result, it has gained popularity over the years because cmake, the software is quite good.

As it happens often, control structures began to creep into the configuration file. This little if won’t hurt anyone, and look, I can do conditional steps during the build file generation with it! How about a for loop? We don’t even have to add an array type, we can just treat strings as arrays! Regex? Sure, add some Cthulhu curse while you are at it. And so on.

Continue Reading...

Murmur3 hash as a constexpr function

C++14 relaxed many restrictions on constexpr functions. The ability to contain branching, loops, switch statements makes them really easy to use. Implementing complicated functions at compile time is now a piece of cake.

To prove this point, I tried and implemented Murmur3A, the Murmur3 hash variant which is optimized for x861 and computes 32 bit hash values. In this post I’m going to walk through the steps of the implementation.

  1. Not that this matters for constexpr; the point is, it computes the same values as that version of the algorithm does.

Continue Reading...

Emulating the static initialization blocks of Java in C++

What is a static initialization block?

In Java, there is a language construct called a static initialization block. The static initialization block will be called the first time the class is loaded by the Java runtime. For example, consider the following code snippet:

class Foo {
    static {
        // initialization code goes here
        // called only once, when the class is loaded by the runtime
        System.out.println("I'm the static initialization block of Foo\n");

    public Foo() {
        System.out.println("I'm the constructor of Foo\n");

    public static void Main(String[] args) {
        Foo foo1 = new Foo();
        Foo foo2 = new Foo();

This produces the output:

I'm the static initialization block of Foo
I'm the constructor of Foo
I'm the constructor of Foo

This construct can be useful in a variety of situations. In Java, the intended use case is to allow multiline initialization of static members of a class. It can also be used for logging and any kind of “registration” or “subscription” code (such as for script binding).

C++ lacks this construct, but with some clever use of the language it’s possible to mimic certain aspects of it.

Continue Reading...