嵌入式 C 编码风格

本文详细介绍了嵌入式C编程的编码风格,包括文件头的许可声明、空格和括号的使用、行长度限制、注释规范、头文件结构、命名规则、函数和变量的处理以及编译要求。特别强调了使用4字节缩进,避免行尾空格,以及遵循Doxygen注释标准来编写公共API的文档。
摘要由CSDN通过智能技术生成

嵌入式 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);
    
  • 表达式的括号必须与

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值