From your first example, it looks like you were looking for singed types.
For unsigned types, I think it might be a bit easier. Here's some ideas - I
haven't tried compiling them to see the code generated, but they might be of
interest.
1) Use a long/struct typedef:
union { unsigned long big; struct { unsigned int counter, overflow; }; }
bigCounter;
Then use "bigCounter.big++" for your increment, and read
bigCounter.counter or bigCounter.overflow as needed. You could make "big"
and "overflow" signed, but not counter (your overflows would occur on the -1
to 0 transition).
2) For unsigned, you can use:
if (!(++counter)) overflow++;
I don't know whether gcc will generate a seperate test for zero, or whether
it can use the flags from the ++counter directly.
3) Your "bit_is_set(SREG, V)" trick should work fine. Use "V" for signed
counters, "C" for unsigned counters.
mvh.
David