如何在c中一行声明多个寄存器变量?
我正在通过保留指向先前和当前节点的指针来实现链表的销毁方法。我想在一行中将它们声明为寄存器变量。是否可以?
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);
}
或者
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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
register
是一个存储类说明符,因此它适用于声明中的所有声明符。它适用于这些示例中的位prev
和curr
。通常,您将存储类说明符放在行的前面(在任何类型说明符之前),但这不是必需的。存储类和类型说明符可以按任意顺序排列(但全部必须位于声明符以及声明符上的任何指针或限定符或其他修饰符之前)
register
is a storage class specifier, so it applies to all the declarators in the declaration. It applies to bitprev
andcurr
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)