[問題] Recommended C coding standards 6ed(已補上)

看板C_and_CPP (C/C++)作者 (brotherD)時間8年前 (2018/01/08 14:38), 8年前編輯推噓2(2022)
留言24則, 5人參與, 8年前最新討論串1/1
圖片: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://www.ptt.cc/bbs/C_and_CPP/M.1515393504.A.CE8.html

01/08 15:47, 8年前 , 1F
紅線是你自己畫的?
01/08 15:47, 1F

01/08 16:18, 8年前 , 2F
應該是接下來放適用於整個文件的defines跟typedefs的意
01/08 16:18, 2F

01/08 16:18, 8年前 , 3F
01/08 16:18, 3F

01/08 18:51, 8年前 , 4F
只有這.c檔用到的define typedef放在所有#include後
01/08 18:51, 4F
奇怪,我記得我有放縮網址,怎麼點進來後不見了@@ ※ 編輯: zzss2003 (60.248.26.157), 01/09/2018 09:17:44

01/09 09:28, 8年前 , 5F
縮網址是 ppt 的話請換一家
01/09 09:28, 5F
我是用Imgur ※ 編輯: zzss2003 (60.248.26.157), 01/09/2018 14:19:31

01/09 14:58, 8年前 , 6F
還是看不到紅線啦 什麼都沒看到
01/09 14:58, 6F
拍謝!已補上! ※ 編輯: zzss2003 (60.248.26.157), 01/10/2018 09:53:58

01/14 01:09, 8年前 , 7F
目前我看到的紅線文字為 If a set of defines
01/14 01:09, 7F

01/14 01:10, 8年前 , 8F
applies to a particular piece of global data
01/14 01:10, 8F

01/14 01:10, 8年前 , 9F
(such as a flags word), the defines should be
01/14 01:10, 9F

01/14 01:10, 8年前 , 10F
immediately after the data declaration or
01/14 01:10, 10F

01/14 01:11, 8年前 , 11F
embedded in structure declarations, indented to
01/14 01:11, 11F

01/14 01:11, 8年前 , 12F
put the defines one level deeper than the first
01/14 01:11, 12F

01/14 01:11, 8年前 , 13F
keyword of the declaration to which they apply.
01/14 01:11, 13F

01/14 01:14, 8年前 , 14F
不負責的解讀成某個資料結構先宣告出來,那些相關的
01/14 01:14, 14F

01/14 01:15, 8年前 , 15F
defines出現的位置,要嘛是在那個 data structure 後
01/14 01:15, 15F

01/14 01:16, 8年前 , 16F
不然就是 embedded 在 structure 裡面並且縮排。
01/14 01:16, 16F

01/14 01:24, 8年前 , 17F
比如說一個 struct audit_context 用某個 enum
01/14 01:24, 17F

01/14 01:24, 8年前 , 18F
audit_context 表示其狀態,他應該在規定那個 enum
01/14 01:24, 18F

01/14 01:25, 8年前 , 19F
出現的次序為何
01/14 01:25, 19F

01/14 01:27, 8年前 , 20F
enum 應該出現在那個 struct 之後或者包在 struct 內
01/14 01:27, 20F

01/14 01:27, 8年前 , 21F
並且要縮排一層
01/14 01:27, 21F

01/14 10:14, 8年前 , 22F
額剛剛看了第三段,他的defines 好像是 macros 那麼
01/14 10:14, 22F

01/14 10:14, 8年前 , 23F
就把例子裡的enum改成#define 不過大概的意思是那樣
01/14 10:14, 23F

01/14 10:14, 8年前 , 24F
沒改變
01/14 10:14, 24F
文章代碼(AID): #1QKn7Wpe (C_and_CPP)
文章代碼(AID): #1QKn7Wpe (C_and_CPP)