Issue
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);
}
Solution
register
is a storage class specifier, so it applies to all the declarators in the declaration. It applies to bit prev
and curr
in these examples.
Commonly, you put storage class specifiers first on the line (before any type specifiers) but that is not required. Storage class and type specifiers can be in any order (but all must be before the declarators and any pointers or qualifiers or other modifiers on the declarator)
Answered By - Chris Dodd Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.