作者zzss2003 (brotherD)
看板C_and_CPP
标题[问题] Recommended C coding standards 6ed
时间Mon Jan 8 14:38:21 2018
图片:
https://imgur.com/a/kopJm
嗨,各位好。小弟最近在念网路上的Recommended C Style and Coding Standards,想说
可以提高程式的可携性、简易debug难度等等。念到一些觉得跟自己观念上有矛盾的内容,
想请教各位的看法。
首先先描述这个file的用途、作者、版本等等,这个没问题,第二个是放header file,也
没问题。
第三点,Any defines and typedefs that apply to the file as a whole are next.这
句我听不太懂是什麽意思。我自己的作法是把defines跟typdefs都放在同一个header档,
然後main.c再include起来。那如果我是用这种方式的话,照作者的意思就是要把这个
header档的顺序排在最後一个罗?
第四点画红线的部分我看不懂,不晓得有版友可以给个例子吗?
谢谢各位!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.248.26.157
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1515393504.A.CE8.html
1F:→ MOONRAKER: 红线是你自己画的? 01/08 15:47
是
2F:→ dannypsnl: 应该是接下来放适用於整个文件的defines跟typedefs的意 01/08 16:18
3F:→ dannypsnl: 思 01/08 16:18
4F:推 Raymond0710: 只有这.c档用到的define typedef放在所有#include後 01/08 18:51
奇怪,我记得我有放缩网址,怎麽点进来後不见了@@
※ 编辑: zzss2003 (60.248.26.157), 01/09/2018 09:17:44
5F:推 LPH66: 缩网址是 ppt 的话请换一家 01/09 09:28
我是用Imgur
※ 编辑: zzss2003 (60.248.26.157), 01/09/2018 14:19:31
6F:→ MOONRAKER: 还是看不到红线啦 什麽都没看到 01/09 14:58
拍谢!已补上!
※ 编辑: zzss2003 (60.248.26.157), 01/10/2018 09:53:58
7F:→ phishingphi: 目前我看到的红线文字为 If a set of defines 01/14 01:09
8F:→ phishingphi: applies to a particular piece of global data 01/14 01:10
9F:→ phishingphi: (such as a flags word), the defines should be 01/14 01:10
10F:→ phishingphi: immediately after the data declaration or 01/14 01:10
11F:→ phishingphi: embedded in structure declarations, indented to 01/14 01:11
12F:→ phishingphi: put the defines one level deeper than the first 01/14 01:11
13F:→ phishingphi: keyword of the declaration to which they apply. 01/14 01:11
14F:→ phishingphi: 不负责的解读成某个资料结构先宣告出来,那些相关的 01/14 01:14
15F:→ phishingphi: defines出现的位置,要嘛是在那个 data structure 後 01/14 01:15
16F:→ phishingphi: 不然就是 embedded 在 structure 里面并且缩排。 01/14 01:16
17F:→ phishingphi: 比如说一个 struct audit_context 用某个 enum 01/14 01:24
18F:→ phishingphi: audit_context 表示其状态,他应该在规定那个 enum 01/14 01:24
19F:→ phishingphi: 出现的次序为何 01/14 01:25
20F:→ phishingphi: enum 应该出现在那个 struct 之後或者包在 struct 内 01/14 01:27
21F:→ phishingphi: 并且要缩排一层 01/14 01:27
22F:→ phishingphi: 额刚刚看了第三段,他的defines 好像是 macros 那麽 01/14 10:14
23F:→ phishingphi: 就把例子里的enum改成#define 不过大概的意思是那样 01/14 10:14
24F:→ phishingphi: 没改变 01/14 10:14