【发布时间】:2014-10-05 04:53:15
【问题描述】:
谁能解释一下为什么在这里:
void
st_clear(st_table *table)
{ //1 a new line
register st_table_entry *ptr, *next;
st_index_t i;
if (table->entries_packed) { //2 the same line
table->num_entries = 0;
table->real_entries = 0;
return;
}
for (i = 0; i < table->num_bins; i++) {
ptr = table->bins[i];
table->bins[i] = 0;
while (ptr != 0) {
next = ptr->next;
st_free_entry(ptr);
ptr = next;
}
}
table->num_entries = 0;
table->head = 0;
table->tail = 0;
}
在一种情况下,他们将{ 留在了同一行,而在另一种情况下则放到了新行?
https://github.com/ruby/ruby/blob/1b5acebef2d447a3dbed6cf5e146fda74b81f10d/st.c
我知道在 C 中没有像大多数其他语言那样明确的命名约定,但在一个项目中总是必须将{ 放在新行中either或留在同一行。
【问题讨论】:
-
这完全是文体。
-
@T.C.,我知道。但必须有一致性。
-
"在一个项目中总是必须在新行或留在同一行"——不,它没有。编译器不在乎。人类可能会,但显然他们不会。
-
@JeffreyBosboom,没有人说过编译器在乎。
-
“总是”听起来像是一个要求。这是a pretty common bracing style - 函数大括号在新行上,其他在同一行上。
标签: c coding-style