Boolean Bits

The C99 standard introduced the _Bool type as well as stdbool.h which allows you to use bool, true and false. _Bool uses a byte to store true/false, yes/no, on/off or whatever the semantics of your program might be, but of course you only really need 1 bit so 7 bits are wasted. Most of the time this isn't worth worrying about but in some rare cases where you need a lot of Booleans it might be worthwhile looking into ways of being a bit more efficient with memory usage. This article presents my particular approach to doing this.

Continue reading

Redirection and Piping

This post will demonstrate programs which each perform a single very specific task but which can be chained together in such a way that the output of one forms the input of another. Connecting programs like this, or piping to use the correct terminology, enables more complex workflows or processes to be run.

This post includes just three short programs to carry out the following tasks:

  • Generating data

  • Filtering data from the data generating program

  • Calculating totals from the filtering program
Continue reading

Star Catalog 1.0

This post covers the first part of a project to develop a star catalog in C. The aims of this initial stage are quite modest - we will write a program to import star data from a file into a data structure and then print it to the screen in a neat format.

Future plans for the project include calculating a few extra pieces of information from existing data, sorting and filtering the data, and exporting it to various other formats.

All these things are specific to stellar data but of course the principles and coding techniques can be applied to any field.

Continue reading

Pascal’s Triangle

The numbers in the graphic below form the first five rows of Pascal's Triangle. The first row consists of a single number 1. In subsequent rows, each of which is has one more number than the previous, values are calculated by adding the two numbers above left and above right. For the first and last values in each row we just take the single value above, therefore these are always 1.

Pascal's Triangle

Pascal's Triangle in its conventional centred layout

(If you do an image search for Pascal's Triangle you will find plenty more, most frequently in a honeycomb grid, sometimes animated, but always nicer than mine. I'm a software engineer, not a graphic designer!)

Continue reading