Andreas Pfohl

My C coding style

Version: 0.1.0

Disclaimer: This post is a “living post”. That means it will be updated from time to time. The version will be increased with every new update and a changelog at the end of the post indicates what has changed.


Over the last years I wrote several programs in the C language. During that period I tried a lot of coding styles until I found the one which works best for me.

In this blog post I describe the most important constructs for programming clean C. There are more constructs that are used less frequent. I intend to describe those in future.

I use at least the C99 standard. It brings some possibilities that are neat to have. You will see later.

Running Kore in production behind nginx proxy

As written in the last post my primary interrest is writing web applications in C with Kore. The post shows how to create a small application and run it in development mode. In production there are two methods to run Kore. The first is to run Kore standalone. That means Kore is directly bound to a port on a public IP address. It is no problem to configure Kore that way because it is intended. But I prefer another way. I want Kore to be a background application to which the requests are routed through a proxy. The purpose of this proxy is to terminate SSL/TLS, do caching and give me the ability to serve different web application from a single IP address.

Writing web software in C with Kore

Do things differently.

Among this statement I was looking for something new for developing websites. Over the last years I used a few languages for doing web development, including ruby and erlang. All these languages have in common that they are abstracted to a point where the user can focus on creating things instead of fiddling around with the language itself. So, to make something different I selected the language I used most of the time for the last year, C. You might have heard that writing web software in C isn’t a good idea. We will see. Part of the journey will be learning a lot about safe programming patterns for the C language and getting a feeling for dangerous code.

HTTP Basic Auth from Database

As you already know you can easily add some authentication to your rails app by adding something like this to any of your controllers.

class ExampleController < ApplicationController
  http_basic_authenticate_with name: "username", password: "secret"

The disadvantage is apparent. You can set only one user. The solution is to add some functionality to your rails app to authenticate against a database model.