【K&RStyle】
krstyle中的k和r分别表示了《The C Programming Language》
的两个作者Kernighan和Ritchie
这种代码风格就是由他们提出的
我挺喜欢这种风格
【书写风格】
1.函数:
[C] 纯文本查看 复制代码 void homo()
{
//Code here
}
2.if...else...else if
[C] 纯文本查看 复制代码 if (ikun = 2.5f){
//Code here
}else if (ikun = 913.0f){
//Code here
}else {
//Code here
}
这里有一种特殊情况,就是如果if占了两行及以上,大括号就要位于下一行(防止混淆)
[C] 纯文本查看 复制代码 if (homo == 114514 ||
homo == 1919810 &&
ikun == 2.5f ||
ikun == 913.0)
{
//Code here
}
3.其它代码(for,while,do...while等)
[C] 纯文本查看 复制代码 for (;;){
//Code here
}
while (1){
//Code here
}
//不列举了
【变量名】
在krstyle中,变量名没有大写
不同单词用下划线链接,如果单词过长,使用简写
[C] 纯文本查看 复制代码 int is_homo();
void swap_str();
int ikun_num;
【不提倡的风格】
1.有参数函数
真的,这太奇怪了,而且只在C语言可用
[C] 纯文本查看 复制代码 int is_homo(homo_num)
int homo_num;{
//Code here
}
奇怪不
2.8格缩进
你们就看看奇不奇怪
[C] 纯文本查看 复制代码 void foo()
{
//Code here
}
要是稍微长一点的代码,直接出屏幕了
|