nortti's microblog

Userscript for fixing (most of) the broken links on The Old New Thing

The Old New Thing is a long-running blog by Raymond Chen that contains a treasure-trove of information on old Windows (among others). Over the years the blog's moved around different domains and backends, which have had the effect of breaking many of the internal links. You can often find your way to the intended post with some URL hackery, but it would be nice not to have to do that, you know?

So because of that I wrote oldnewthing-link-unfucker, which automates most of the work. If it recognizes a link pointing to an old url it'll rewrite it to point to the modern URL for the post, or failing that, the day it was posted. Any URL thus modified will get a 𝌡 (the Taixuanjing tetragram for 'change') after it to mark it's been changed.

It's a userscript, so to use it paste it to any userscript manager you like. I use GreaseMonkey.

Self-referential variable initialization in C

I was reading the SDL Shader Language Quickstart, which (at the moment) mostly consists of explanations about how the language differs from C.

One difference listed caught my eye: variable initialization can't reference itself. To quote,

Why does C even allow this?

int x = x + 1;

In C, x is in scope as soon as the parser sees int x, but this allows you to reference a variable that is definitely not initialized during its own initializer! Doing so is always a bug, so we just don't allow it.

I would consider myself fairly knowledgeable about the weird corners of C, but I had never come across this "feature"!

As stated, using the uninitialized value of the variable is going to be undefined behaviour in C. However, I did not immediately see why taking a pointer to the variable would be. So, as long as we only use the pointer of the value in its definition, that ought to be fine?

Normally, doing

type x = &x;

is going to fail because the types type and type* are not compatible. However, in C (but not C++!) you can implicitly cast between void* and any other pointer type, including void**. This means we should be able to do

void *x = &x;

To test this, I made the following test program

#include <stdio.h>

int main(void) {
	void *x = &x;
	// We need an explicit cast for &x here, since printf is a
	// varargs function.
	printf("x = %p, &x = %p\n", x, (void*)&x);
}

And with GCC 14.2.0, this does indeed work, with zero warnings with the flags -std=c23 -Wall -Wextra -pedantic!

First post

This is meant to be a microblog in the style of zunzuncito, a microblog run by my partner. The posts here are going to be lower-effort than what you'd see over either on zunzuncito or my writeups – I hope to have this be a replacement for social media for me.

At the moment the site is extremely bare-bones, but I hope to add support for h-entry based embeddings and a comment section (maybe using Cusdis?). In the meantime, if you want to comment on anything here, send me an e-mail.