July 15, 2019

Generating markdown changelogs using git

Sometimes I want to create changelogs for my personal projects and add them to blog posts. It’s extra neat to have all changelog entries link to individual commits on GitHub. git log allows you to specify a custom format, and is perfect for the task: $ git log --pretty=format:"* [%s](https://github.com/olehermanse/mrpg/commit/%H)" 09facd30..HEAD Update the GitHub URL with your project, and the commit SHA with the last commit from the previous changelog. The log will have newest changes first, and won’t include the commit which the SHA references, only commits since then. This fits well if you want to maintain a changelog file with the most recent version first. (Use the --reverse option if you prefer older changes first). You can also use a tag: Read more

November 11, 2018

Scanning unsigned types in C

printf and scanf are the C standard library functions for printing out and reading in data. They have string counterparts, prefixed with s, which work on strings (sprintf and sscanf). All these functions use a format string to match parts of the string with C variables. As an example, %lu in the format string corresponds to an unsigned long, a positive integer type in C. Scanning unsigned types What happens if you try to sscanf a negative number using %lu? printf will never print a negative number for %lu so sscanf should not scan one, right? Unfortunately, sscanf does match negative numbers for unsigned format strings. As an example, we can scan "-10" with format "%lu": Read more

October 20, 2018

Unknown type name 'u_int'

I ran across the error message (Unknown type name 'u_int', 'u_long', 'u_char' etc.) when trying to incorporate some old C code into a more modern project. It shows up in system headers, like sys/attr.h, and I was confused. After quite some time I figured out what the problem was, so I thought I’d share. Simplified example The source code, when simplified, looked something like this (test.c): #define _XOPEN_SOURCE 500 #include <sys/attr.h> #include <stdio.h> int main(void) { printf("Hello, world!"); } Compiler output When compiled in GCC, on OS X, you get errors from the included file sys/attr.h: Read more

October 6, 2018

AddressSanitizer (ASAN) examples

AddressSanitizer is a great tool for finding bugs in C or C++ projects. It consists of some instrumentation added to code at compile time, as well as a dynamically linked runtime. Good test coverage is required, as it detects problems at runtime, while running your test-suite. To use it, supply -fsanitize=address to both the compiler and linker when building for tests (works in newer versions of clang and gcc). There are great resources for understanding how it works, but when I started, I was missing a few simple examples. Read more

© Ole Herman Schumacher Elgesem 2025

Powered by Hugo & Kiss.