I'm implementing destroy method for a linked list by keeping pointers to previous and current nodes. I'd like to declare them as register variables in a single line. Is it possible?
void list_destroy(list *ls) {
// does this mean both prev and curr are register variables?
register node *prev, *curr;
for (prev = 0, curr = ls; curr != 0; curr = curr->next) {
if (prev != 0)
free(prev);
prev = curr;
}
free(ls);
}
or
void list_destroy(list *ls) {
node register *prev, *curr;
for (prev = 0, curr = ls; curr != 0; curr = curr->next) {
if (prev != 0)
free(prev);
prev = curr;
}
free(ls);
}
register
is a keyword in C — just like you never useauto
either. The compiler will make register assignments on it's own, better than you can, and it will largely if not completely ignore your use of the keyword.register
from this function.