Evan Teran's Blog

Adventures in non-deterministic code (Always initialized your structs!)

I've been working on an old code base lately. It's a relatively simple data in/data out, kinda program. But It's also a bit messy, written in C using outdated techniques, and suffers from memory leaks. So I am going through the process of cleaning it up and porting it to C++ so the code can be made simpler and easier to manage.

Being that I didn't write the original code, my first thought was to create some sort of regression tests. My plan was simple. Run the code on a bunch of varied input files, and save the output. Now, every subsequent run I can just diff the results with the "known good" ones and I should be good to go... right?

Sadly, this was not the case.

Read More...

Moving printf into the modern age using C++17

Ever since c++11 introduce variadic templates, I started seeing people implement some "safe printf" examples. They are pretty cool, but none of them attempted to actually implement the printf fully with all of its quirks. Instead, they all pretty much do the same thing:

  1. Use variadic templates to verify the sanity of the parameters
  2. Delegate the actual formatting to the libc printf

I think we can do better...

Read More...

Well This Is Embarrassing (I Got Hacked)

I suppose it happens to everyone eventually. My blog got hacked. :-/

Read More...

Portable BitFields Using C++11

There are lots of reasons to using C++'s bit field feature. Perhaps you need a more compact way to represent your data structures, maybe you need to use them interact with hardware, or if you're writing an emulator, maybe you want to use them to efficiently represent the hardware that you're emulating. The list goes on...

Read More...

A bit about fixed sized dialogs in Qt

Most of the time, it makes the most sense for our dialogs to be designed with layouts such that it looks good with just about any width or height. But there are a few cases where locking in the size makes sense. The most classic example I can think of is an "about this application" dialog box.

Read More...