Interesting gcc/clang extensions to C
Both gcc and clang support extensions to C and while i normally try and make things I write about work on Windows (i.e. Visual Studio), these are useful enough that I thought they deserve a mention. Yes I know you can run gcc/clang on Windows using Cygwin or MinGW, but for various reasons I prefer Visual Studio.
You can add a constructor and destructor functions to a C program; the constructor function runs before main() and the destructor after main().
The syntax is not exactly clean or obvious (those are double underscores before and after the word attribute like Python dunders!) but I got this program to compile/run with clang 10 on Ubuntu as the screenshot shows. Here’s a listing. I called the two functions ctor and dtor but you can use anything.
#include <stdio.h>
__attribute__((constructor)) void ctor(void)
{
printf("Constructor runs first\n");
}
__attribute__((destructor)) void dtor(void)
{
printf("Destructor runs last\n");
}
int main() {
printf("Main\n");
}
The output is:
david@DavidPC:~/Projects/Examples$ ./ex1 Constructor runs first Main Destructor runs last


I always wanted to do this and have most of it done. It just needs a bit of polishing plus making it cross-platform. It wasn’t the hardest thing I’ve done although I did start by trying to make the common part for asteroids, player ship, bullets and aliens, the bit that managed position and velocity into a base class.
I was curious as to how many C extensions there are for VS Code. If you visit the 
If you remember back in November I mentioned a 

Core war is an old game concept that dates back to 1984. If you imagine a simple CPU with small programs written in assembly language trying to wipe each other out, that’s Core War and you can read about it in a lot more detail o