The _Generic Keyword

The C11 standard added the “underscore” bunch to the C language’s traditional keywords:

_Alignas
_Alingof
_Atomic
_Bool
_Complex
_Generic
_Imaginary
_Noreturn
_Static_assert
_Thread_local

I don’t routinely use any of these in my programs, beyond trying a few out to see how they work. The _Bool keyword comes in handy. The rest? Well, they’re worth exploring from a curiosity standpoint. For this week’s Lesson, I reveal the mysteries of the _Generic keyword.
Continue reading

Balancing Accounts

Difficulty: Medium

Your bank receives two deposits or credits and three bills or debits. The credits cover the debits, meaning that your balance should never go below zero, but the bank has clever software: The bills are calculated first, which thrusts your account into negative territory complete with fees — even though the deposits cover the bills. Is this obnoxious behavior the result of greedy bankers or clever programming?
Continue reading