Merge tag '5.15-rc-cifs-part2' of git://git.samba.org/sfrench/cifs-2.6
[linux-2.6-microblaze.git] / Documentation / translations / zh_TW / sparse.txt
1 Chinese translated version of Documentation/dev-tools/sparse.rst
2
3 If you have any comment or update to the content, please contact the
4 original document maintainer directly.  However, if you have a problem
5 communicating in English you can also ask the Chinese maintainer for
6 help.  Contact the Chinese maintainer if this translation is outdated
7 or if there is a problem with the translation.
8
9 Traditional Chinese maintainer: Hu Haowen <src.res@email.cn>
10 ---------------------------------------------------------------------
11 Documentation/dev-tools/sparse.rst 的繁體中文翻譯
12
13 如果想評論或更新本文的內容,請直接聯繫原文檔的維護者。如果你使用英文
14 交流有困難的話,也可以向繁體中文版維護者求助。如果本翻譯更新不及時或
15 者翻譯存在問題,請聯繫繁體中文版維護者。
16
17 繁體中文版維護者: 胡皓文 Hu Haowen <src.res@email.cn>
18 繁體中文版翻譯者: 胡皓文 Hu Haowen <src.res@email.cn>
19
20 以下爲正文
21 ---------------------------------------------------------------------
22
23 Copyright 2004 Linus Torvalds
24 Copyright 2004 Pavel Machek <pavel@ucw.cz>
25 Copyright 2006 Bob Copeland <me@bobcopeland.com>
26
27 使用 sparse 工具做類型檢查
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~
29
30 "__bitwise" 是一種類型屬性,所以你應該這樣使用它:
31
32         typedef int __bitwise pm_request_t;
33
34         enum pm_request {
35                 PM_SUSPEND = (__force pm_request_t) 1,
36                 PM_RESUME = (__force pm_request_t) 2
37         };
38
39 這樣會使 PM_SUSPEND 和 PM_RESUME 成爲位方式(bitwise)整數(使用"__force"
40 是因爲 sparse 會抱怨改變位方式的類型轉換,但是這裡我們確實需要強制進行轉
41 換)。而且因爲所有枚舉值都使用了相同的類型,這裡的"enum pm_request"也將
42 會使用那個類型做爲底層實現。
43
44 而且使用 gcc 編譯的時候,所有的 __bitwise/__force 都會消失,最後在 gcc
45 看來它們只不過是普通的整數。
46
47 坦白來說,你並不需要使用枚舉類型。上面那些實際都可以濃縮成一個特殊的"int
48 __bitwise"類型。
49
50 所以更簡單的辦法只要這樣做:
51
52         typedef int __bitwise pm_request_t;
53
54         #define PM_SUSPEND ((__force pm_request_t) 1)
55         #define PM_RESUME ((__force pm_request_t) 2)
56
57 現在你就有了嚴格的類型檢查所需要的所有基礎架構。
58
59 一個小提醒:常數整數"0"是特殊的。你可以直接把常數零當作位方式整數使用而
60 不用擔心 sparse 會抱怨。這是因爲"bitwise"(恰如其名)是用來確保不同位方
61 式類型不會被弄混(小尾模式,大尾模式,cpu尾模式,或者其他),對他們來說
62 常數"0"確實是特殊的。
63
64 獲取 sparse 工具
65 ~~~~~~~~~~~~~~~~
66
67 你可以從 Sparse 的主頁獲取最新的發布版本:
68
69         http://www.kernel.org/pub/linux/kernel/people/josh/sparse/
70
71 或者,你也可以使用 git 克隆最新的 sparse 開發版本:
72
73         git://git.kernel.org/pub/scm/linux/kernel/git/josh/sparse.git
74
75 一旦你下載了源碼,只要以普通用戶身份運行:
76
77         make
78         make install
79
80 它將會被自動安裝到你的 ~/bin 目錄下。
81
82 使用 sparse 工具
83 ~~~~~~~~~~~~~~~~
84
85 用"make C=1"命令來編譯內核,會對所有重新編譯的 C 文件使用 sparse 工具。
86 或者使用"make C=2"命令,無論文件是否被重新編譯都會對其使用 sparse 工具。
87 如果你已經編譯了內核,用後一種方式可以很快地檢查整個源碼樹。
88
89 make 的可選變量 CHECKFLAGS 可以用來向 sparse 工具傳遞參數。編譯系統會自
90 動向 sparse 工具傳遞 -Wbitwise 參數。
91