我刚刚遇到了一些过度使用分号的代码,或者使用分号用于我不知道的不同目的.
我在if语句的末尾和函数的末尾发现了分号.例如:
int main (int argc, char * argv[]) {
// some code
if (x == NULL) {
// some code
}; <-----
// more code
return 0;
}; <---
Run Code Online (Sandbox Code Playgroud)
它用cc编译,而不是gcc.那些分号做了什么?我假设没有区别,因为编译器只会将其视为空语句.
Jon*_*eet 33
他们什么都不做.我怀疑,他们是一个非常不懂语言的人的标志.
如果这是源代码,你理所当然地"拥有",我会删除代码,并尝试与编写它的人轻轻聊天.
这是虚拟状态.你的样本与之相同
if (x == NULL) {
// some code
do_something_here();
}
/* empty (dummy statement) here */ ;
// more code
some_other_code_here();
Run Code Online (Sandbox Code Playgroud)