C 源文件模板

C 源文件模板

Written By Tomy Stark.
E-mail: ro7enkranz@qq.com
Ver 1.0.0

Note:

  • 转载请注明本文出处链接、作者

Eclipse 系 IDE 自动化

1. Eclipse 系 IDE 新建.c文件和.h文件时自动添加头部Comments

  • Window -> Preference -> C/C++ -> Code Style -> Code Templates -> Comments -> Files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* _____ ___ ___ ___ ___ ___ ___
* / /::\ / /\ / /\ / /\ /__/\ ___ / /\ /__/|
* / /:/\:\ / /::\ / /:/_ / /::\ \ \:\ / /\ / /:/_ | |:|
* / /:/ \:\ / /:/\:\ / /:/ /\ / /:/\:\ \ \:\ / /:/ / /:/ /\ | |:|
* /__/:/ \__\:| / /:/ \:\ / /:/ /::\ / /:/ \:\ _____\__\:\ / /:/ / /:/ /:/_ __| |:|
* \ \:\ / /:/ /__/:/ \__\:\ /__/:/ /:/\:\ /__/:/ \__\:\ /__/::::::::\ / /::\ /__/:/ /:/ /\ /__/\_|:|____
* \ \:\ /:/ \ \:\ / /:/ \ \:\/:/~/:/ \ \:\ / /:/ \ \:\~~\~~\/ /__/:/\:\ \ \:\/:/ /:/ \ \:\/:::::/
* \ \:\/:/ \ \:\ /:/ \ \::/ /:/ \ \:\ /:/ \ \:\ ~~~ \__\/ \:\ \ \::/ /:/ \ \::/~~~~
* \ \::/ \ \:\/:/ \__\/ /:/ \ \:\/:/ \ \:\ \ \:\ \ \:\/:/ \ \:\
* \__\/ \ \::/ /__/:/ \ \::/ \ \:\ \__\/ \ \::/ \ \:\
* \__\/ \__\/ \__\/ \__\/ \__\/ \__\/
*
*
* @ 名称: ${file_name}
* @ 描述:
* @ 作者: ${user}
* @ 日期: ${date}
* @ 版本: V1.0
* @ 历史: V1.0 ${date} Summary
*
* Copyright (c) 2019 DosonTek Electronics Co., Ltd. All rights reserved.
*/
阅读更多
Astyle 参数设置

Astyle 参数设置

Written By Tomy Stark.
E-mail: ro7enkranz@qq.com
Ver 1.0.0

Note:

  • 转载请注明本文出处链接、作者

A. *.bat批处理文件调用Astyle进行代码格式化[KR风格]

1. 一键格式化所有代码(包括子目录)_完整参数版

1
2
for /R %%f in (*.c;*.h) do AStyle.exe --style=kr --indent=spaces=4 --attach-closing-while --indent-switches --indent-preproc-define --indent-col1-comments --max-continuation-indent=60 --break-blocks --pad-oper --pad-comma --pad-header --align-pointer=name --align-reference=name --break-one-line-headers --add-braces --attach-return-type --attach-return-type-decl --convert-tabs --max-code-length=200 --suffix=none --verbose %%f
pause
阅读更多
MISRA-C 2004 规则解读

MISRA-C 2004 规则解读

Written By Tomy Stark.
E-mail: ro7enkranz@qq.com
Ver 1.0.0

Note:

  • 本标准会不定期迭代完善
  • 本文档由我从互联网整理收集而来,尚需完善,文中可能还存在诸多谬误,若发现有误可邮件联系以修正问题,在此感谢!

1 S ~ 20 S

1 S:Procedure name reused.函数名与变量名称重复。

2 S:Label name reused.局部变量重命名。虽然作用域不同能编译通过,但是容易造成混淆。

3 S:More than N executable reformatted lines in file.规定单个文件代码行数不能超过N,N值可配置。

4 S:Procedure exceeds N reformatted lines.规定单个函数的代码行数不能超过N,N值可配置。

5 S:Empty then clause.空语句有可能是开发人员忘记实现某个功能而留下的坑。所以在确实是空的地方这样写比较合适:

1
2
3
4
5
6
7
UINT_32 value_x = 1u;

if (value_x == 0u) {
value_x = value_x + 1u;
} else
/*do nothing*/

阅读更多
C语言开发标准(微控制器)