The ring buffer is a nice trick, but it only works on array sizes that are a multiple of 2. The generalized version would be "array[i++ % ARRAY_SIZE] = data". If ARRAY_SIZE happens to be a multiple of two, I'm sure most compilers would optimize to a bitmask anyways..
And if it is not a power of 2, the % operation will be anything but fast. If a size not a power of 2 is strictly required, a simple increment and compare is almost certainly faster.
Signed integer overflow is undefined, so make sure you're using an unsigned type in your ringbuffer example. (And an array with some-power-of-2 elements; you should probably use sizeof(array)/sizeof(<star> array) instead of ARRAY_SIZE too.)
No. ~0 has type signed int, which on a one's complement machine is a negative zero. Converting this to an unsigned type yields zero. On a sign-magnitude machine, ~0 is -0x7fffffff (assuming 32-bit for simplicity). Conversion to unsigned 32-bit is done by adding 0x100000000, yielding 0x80000001, again not what was desired. If the variable being assigned to has a width different from that of int, things get even more interesting.
As far as I know analog devices still makes some ones-complement Analog to Digital Converters. But I don't know of any modern processor that uses them.
That will only set as many bits as are in an int, which is wrong if the type of the variable you are setting is wider than int. For a long, you could of course use ~0ul, and so on for other types, but then you'd have to find and update every such assignment if the variable were ever changed to a wider type.
Convert single char c into an integer:
Get the length of a static string you can use sizeof() instead of strlen() A fast and simple ring buffer (borrowed from Quake code) Init all bits of a mask to 1 on any architecture: