About four years ago, the ISO 9899:2011 "C11" standard was announced. At the time, I had a short look at (a draft version of) the standards document, and found a few interesting bits in there. Of course, however, due to it only very recently having been released, I did not have much hope of it being implemented to any reasonable amount anywhere yet. Which turned out to be the case. Even if that wasn't true, writing code that uses C11 features and expecting it to work just about anywhere else would have been a bad idea back then.

We're several years down the line now, however, and now the standard has been implemented to a reasonable extent in most compilers. GCC claims its "support [for C11] is at a similar level of completeness to (...) C99 support" since GCC 4.9.

Since my laptop has GCC 4.9, I looked at one feature in C11 that I have been wanting to use for a while: Generic selection.

#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

void say32(uint32_t i) {
    printf("32-bit variable: %" PRId32 "\n", i);
}

void say64(uint64_t i) {
    printf("64-bit variable: %" PRId64 "\n", i);
}

void sayother(int i) {
    printf("This is something else.\n");
}

#define say(X) _Generic((X), uint32_t: say32, uint64_t: say64, default: sayother)(X)

int main(void) {
    uint32_t v32 = 32;
    uint64_t v64 = 64;
    uint8_t v8 = 8;

    say(v32);
    say(v64);
    say(v8);
}

Output of the above:

32-bit variable: 32
64-bit variable: 64
This is something else.

or, "precompiler-assisted function overloading for C". Should be useful for things like:

#define ntoh(X) _Generic((X), int16_t: ntohs, uint16_t: ntohs, int32_t: ntohl, uint32_t: ntohl)(X)
#define hton(X) _Generic((X), int16_t: ntohs, uint16_t: htons, int32_t: ntohl, uint32_t: htonl)(X)

... and if one adds the ntohll found here, it can do 64 bit as well.