int will cause undefined behaviour when it overflows, unsigned won't.
But why, oh why, are people proposing these fancy
power-of-2-based-modulo-or-masking-solutions over the oft offered:
i = 1 - i;
?
Because beauty is in the eye of the beholder and there may be people
who happen to like other solutions better.
The modulus solution below has the clear advantage of being scalable to
larger array sizes.
#define ARRAY_SIZE 2
int index (void) {
static int i = 0;
return i = (i + 1) % ARRAY_SIZE;
}
If I were absolutely sure that I'll never need a larger array I'd go
with another offered solution:
int index (void) {
static int i = 1;
return i = !i;
}
which in turn has the advantage that if i somehow (wild pointers,
buffer overflow...) gets a value different than 0 or 1, it will return
to sequence in the next call (the damage may have been done by now, but
that's another matter).