int alloc_id() { int i, j; int bit = sizeof(idr.id_word[0]) * 8; for (i = 0; i < 10; i++) { for (j = 0; j < bit; j++) { if (!(idr.id_word[i] & (1UL << j)))
{ idr.id_word[i] |= (1UL << j); return i * bit + j; } } }
return -1; }
void remove_id(int id) { int i, bit; i = id / (sizeof(idr.id_word[0]) *
8); bit = id % (sizeof(idr.id_word[0]) * 8); idr.id_word[i] &= ~(1UL << bit); }
int main(void) { int i; int id1, id2, id3; for (i = 0; i < 10 * sizeof(idr.id_word[0]) * 8 + 1; i++) { printf("[%d]id = %d\n", i, alloc_id()); }