Common C programming mistakes

Posted on Sun 27 September 2015 in blog

I've decided to compile a list of common programming mistakes when using C.

Random numbers

Q: Why is my program generating the same random numbers?
A: You're probably re-seeding the PRNG. You should call srand() just once, at the beginning of your program. From then on, just avoid concurrent accesses …

Continue reading

Gotta catch 'em all: Last-chance exception handling in .NET with WinForms

Posted on Thu 07 March 2013 in blog

Recently, I went through the exercise of hooking up a crash-reporting component to a large .NET application using Windows Forms. The goal, of course, is to catch all unhandled exceptions so they can be reported to the developer.

Throughout this post I'll be referring to this Program.cs:

The code …

Continue reading

goto: The Forbidden Fruit

Posted on Mon 25 February 2013 in blog

Nowdays, it's not hard to find tons of arguments against the use of goto in C (and C-like languages). Post anything to StackOverflow, about/including goto and you're almost guaranteed to get flamed.

XKCD comic: goto

Just like many good and useful things in our lives (pocketknives, guns, kegs, etc.) it only takes …

Continue reading

Named Pipes between C# and Python

Posted on Thu 13 December 2012 in blog

There's a lot of over-complicated information on the internet for communicating between a C# process and a Python process using named pipes on Windows. I'll start with the code:

In this example, I implement a very simple protocol, where every "message" is a 4-byte integer (UInt32 in C#, I (un …

Continue reading

Never knew Downloader.Agent2.BBLD was so simple

Posted on Sun 29 April 2012 in blog

I had just started writing a new C++ console app (under Visual Studio 2010 10.0.40219.1 SP1Rel) to test something out, and had just this:

#include <stdio.h>
#include <Windows.h>

int main(int argc, char** argv)
    return 0;

I unintentionally clicked Start Debugging, and much to my …

Continue reading