嵌入式 C 编码风格
版本 | 日期 | 作者 | 备注 |
---|---|---|---|
V1.0 | 2019.09.16 | Like Shadows | 初版 |
文件头
-
所有新建的文件,都必须在最开始声明 Project 的许可条款。
-
对于从其它地方拷贝的文件,如果有许可条款声明,则应保留。
Project 的许可条款示例如下:
/* * Copyright [2019] [xxxx Co., Ltd] * * Licensed under the Apache License, Version 2.0 (the "License"), * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.xxxx.com * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */
空格和括号
-
代码必须以 4 字节缩进,不建议采用 TAB 缩进。
-
不允许在行尾添加空格。
-
关键字后面需要添加空格 (如:for,if,return,switch,while)。
-
for,else,if,while,表达式必须使用大括号
//正确 if (x) { assert(0); } else { assert(0); } //错误 if (x) assert(0); else assert(0);
-
表达式的括号必须与