update for test
[gocoso.git] / CodingStyle
blob117b2d9edd7977cab49865a687b363473f5eada6
1 我想我编写代码的时候应该采用kernel的代码风格,所以就拷贝了一份,下面是内核代码的风格,如果有人愿意和我一起编写这个简单的软件,我希望也是采用下面的风格。我们作就要做得更好,小了才更加容易让我们作好,和打好基础。希望,有很多的人参与。
2 msgid "\t\tLinux kernel coding style\n"
3 msgstr "\t\tLinux内核代码风格\n"
5 msgid ""
6 "This is a short document describing the preferred coding style for the "
7 "linux kernel.  Coding style is very personal, and I won't _force_ my views "
8 "on anybody, but this is what goes for anything that I have to be able to "
9 "maintain, and I'd prefer it for most other things too.  Please at least "
10 "consider the points made here."
11 msgstr ""
12 "这是一个简短的文档,描述了linux内核的首选代码风格。代码风格是因人而异的,而"
13 "且我不会把我的观点强加给任何人,不过这里所讲述的是我必须能够维护的代码所遵守"
14 "的风格,并且我也希望绝大多数其他代码也能遵守这个风格。请在写代码时至少考虑一"
15 "下本文所述的风格。"
17 msgid ""
18 "First off, I'd suggest printing out a copy of the GNU coding standards, and "
19 "NOT read it.  Burn them, it's a great symbolic gesture."
20 msgstr ""
21 "首先,我建议你打印一份GNU代码规范,然后不要读它。烧了它,这是一个意义重大的"
22 "象征性的姿态。"
24 msgid "Anyway, here goes:"
25 msgstr "不管怎样,现在我们开始:"
27 msgid "\t \tChapter 1: Indentation\n"
28 msgstr "\t \t第一章:缩进\n"
30 msgid ""
31 "Tabs are 8 characters, and thus indentations are also 8 characters.  There "
32 "are heretic movements that try to make indentations 4 (or even 2!)  "
33 "characters deep, and that is akin to trying to define the value of PI to be "
34 "3."
35 msgstr ""
36 "制表符是8个字符,所以缩进也是8个字符。有些异端运动试图将缩进变为4(乃至2)个"
37 "字符深,这几乎相当于尝试将圆周率的值定义为3。"
39 msgid ""
40 "Rationale: The whole idea behind indentation is to clearly define where a "
41 "block of control starts and ends.  Especially when you've been looking at "
42 "your screen for 20 straight hours, you'll find it a lot easier to see how "
43 "the indentation works if you have large indentations."
44 msgstr ""
45 "理由:缩进的全部意图就是清楚的定义一个控制块起止于何处。尤其是当你盯着你的屏"
46 "幕连续看了20小时之后,你将会发现大一点的缩进将会使你更容易分辨缩进。"
48 msgid ""
49 "Now, some people will claim that having 8-character indentations makes the "
50 "code move too far to the right, and makes it hard to read on a 80-character "
51 "terminal screen.  The answer to that is that if you need more than 3 levels "
52 "of indentation, you're screwed anyway, and should fix your program."
53 msgstr ""
54 "现在,有些人会抱怨8个字符的缩进会使代码向右边移动的太远,在80个字符的终端屏"
55 "幕上就很难读这样的代码。这个问题的答案是,如果你需要3级以上的缩进,不管缩进"
56 "深度如何,你的代码已经有问题了,应该修正你的程序。"
58 msgid ""
59 "In short, 8-char indents make things easier to read, and have the added "
60 "benefit of warning you when you're nesting your functions too deep.  Heed "
61 "that warning."
62 msgstr ""
63 "简而言之,8个字符的缩进可以让代码更容易阅读,还有一个好处是当你的函数嵌套太"
64 "深的时候可以给你警告。留心这个警告。"
66 msgid ""
67 "The preferred way to ease multiple indentation levels in a switch statement "
68 "is to align the \"switch\" and its subordinate \"case\" labels in the same "
69 "column instead of \"double-indenting\" the \"case\" labels.  E.g.:"
70 msgstr ""
71 "在switch语句中消除多级缩进的首选方式是让“switch”和从属于它的“case”标签对齐"
72 "于同一列,而不要“两次缩进”“case”标签。比如:"
74 msgid ""
75 "\tswitch (suffix) {\n"
76 "\tcase 'G':\n"
77 "\tcase 'g':\n"
78 "\t\tmem <<= 30;\n"
79 "\t\tbreak;\n"
80 "\tcase 'M':\n"
81 "\tcase 'm':\n"
82 "\t\tmem <<= 20;\n"
83 "\t\tbreak;\n"
84 "\tcase 'K':\n"
85 "\tcase 'k':\n"
86 "\t\tmem <<= 10;\n"
87 "\t\t/* fall through */\n"
88 "\tdefault:\n"
89 "\t\tbreak;\n"
90 "\t}\n"
91 msgstr ""
92 "\tswitch (suffix) {\n"
93 "\tcase 'G':\n"
94 "\tcase 'g':\n"
95 "\t\tmem <<= 30;\n"
96 "\t\tbreak;\n"
97 "\tcase 'M':\n"
98 "\tcase 'm':\n"
99 "\t\tmem <<= 20;\n"
100 "\t\tbreak;\n"
101 "\tcase 'K':\n"
102 "\tcase 'k':\n"
103 "\t\tmem <<= 10;\n"
104 "\t\t/* fall through */\n"
105 "\tdefault:\n"
106 "\t\tbreak;\n"
107 "\t}\n"
109 msgid ""
110 "Don't put multiple statements on a single line unless you have something to "
111 "hide:"
112 msgstr "不要把多个语句放在一行里,除非你有什么东西要隐藏:"
114 msgid ""
115 "\tif (condition) do_this;\n"
116 "\t  do_something_everytime;\n"
117 msgstr ""
118 "\tif (condition) do_this;\n"
119 "\t  do_something_everytime;\n"
121 msgid ""
122 "Don't put multiple assignments on a single line either.  Kernel coding "
123 "style is super simple.  Avoid tricky expressions."
124 msgstr ""
125 "也不要在一行里放多个赋值语句。内核代码风格超级简单。就是避免可能误导别人的表"
126 "达方式。"
128 msgid ""
129 "Outside of comments, documentation and except in Kconfig, spaces are never "
130 "used for indentation, and the above example is deliberately broken."
131 msgstr ""
132 "除了注释、文档和Kconfig之外,不要使用空格来缩进,前面的例子是例外,是有意为"
133 "之。"
135 msgid "Get a decent editor and don't leave whitespace at the end of lines."
136 msgstr "选用一个好的编辑器,不要在行尾留空格。"
138 msgid "\t\tChapter 2: Breaking long lines and strings\n"
139 msgstr "\t\t第二章:打散长的行和字符串\n"
141 msgid ""
142 "Coding style is all about readability and maintainability using commonly "
143 "available tools."
144 msgstr "代码风格的意义就在于使用平常使用的工具来维持代码的可读性和可维护性。"
146 msgid ""
147 "The limit on the length of lines is 80 columns and this is a hard limit."
148 msgstr "每一行的长度的限制是80列,而且这是一个硬性的规定。"
150 msgid ""
151 "Statements longer than 80 columns will be broken into sensible chunks.  "
152 "Descendants are always substantially shorter than the parent and are placed "
153 "substantially to the right. The same applies to function headers with a "
154 "long argument list. Long strings are as well broken into shorter strings."
155 msgstr ""
156 "长于80列的语句要打散成有意义的片段。每个片段要明显短于原来的语句,而且要明显"
157 "的往右放置。同样的规则也应用于有很长参数列表的函数头。长字符串也要打散成较短"
158 "的字符串。"
160 msgid ""
161 "void fun(int a, int b, int c)\n"
162 "{\n"
163 "\tif (condition)\n"
164 "\t\tprintk(KERN_WARNING \"Warning this is a long printk with \"\n"
165 "\t\t\t\t\t\t\"3 parameters a: %u b: %u \"\n"
166 "\t\t\t\t\t\t\"c: %u \\n\", a, b, c);\n"
167 "\telse\n"
168 "\t\tnext_statement;\n"
169 "}\n"
170 msgstr ""
171 "void fun(int a, int b, int c)\n"
172 "{\n"
173 "\tif (condition)\n"
174 "\t\tprintk(KERN_WARNING \"Warning this is a long printk with \"\n"
175 "\t\t\t\t\t\t\"3 parameters a: %u b: %u \"\n"
176 "\t\t\t\t\t\t\"c: %u \\n\", a, b, c);\n"
177 "\telse\n"
178 "\t\tnext_statement;\n"
179 "}\n"
181 msgid "\t\tChapter 3: Placing Braces and Spaces\n"
182 msgstr "\t\t第三章:大括号和空格的放置\n"
184 msgid ""
185 "The other issue that always comes up in C styling is the placement of "
186 "braces.  Unlike the indent size, there are few technical reasons to choose "
187 "one placement strategy over the other, but the preferred way, as shown to "
188 "us by the prophets Kernighan and Ritchie, is to put the opening brace last "
189 "on the line, and put the closing brace first, thusly:"
190 msgstr ""
191 "C语言风格中另外一个常见问题是大括号的放置。和缩进大小不同,选择某种放置策略"
192 "而弃用其他策略并没有多少技术上的原因,不过首选的方式,就像Kernighan和Ritchie"
193 "展示给我们的,是把起始大括号放在行尾,而把结束大括号放在行首,所以:"
195 msgid ""
196 "\tif (x is true) {\n"
197 "\t\twe do y\n"
198 "\t}\n"
199 msgstr ""
200 "\tif (x is true) {\n"
201 "\t\twe do y\n"
202 "\t}\n"
204 msgid ""
205 "This applies to all non-function statement blocks (if, switch, for, while, "
206 "do).  E.g.:"
207 msgstr "这适用于所有的非函数语句块(if、switch、for、while、do)。比如:"
209 msgid ""
210 "\tswitch (action) {\n"
211 "\tcase KOBJ_ADD:\n"
212 "\t\treturn \"add\";\n"
213 "\tcase KOBJ_REMOVE:\n"
214 "\t\treturn \"remove\";\n"
215 "\tcase KOBJ_CHANGE:\n"
216 "\t\treturn \"change\";\n"
217 "\tdefault:\n"
218 "\t\treturn NULL;\n"
219 "\t}\n"
220 msgstr ""
221 "\tswitch (action) {\n"
222 "\tcase KOBJ_ADD:\n"
223 "\t\treturn \"add\";\n"
224 "\tcase KOBJ_REMOVE:\n"
225 "\t\treturn \"remove\";\n"
226 "\tcase KOBJ_CHANGE:\n"
227 "\t\treturn \"change\";\n"
228 "\tdefault:\n"
229 "\t\treturn NULL;\n"
230 "\t}\n"
232 msgid ""
233 "However, there is one special case, namely functions: they have the opening "
234 "brace at the beginning of the next line, thus:"
235 msgstr ""
236 "不过,有一个例外,那就是函数:函数的起始大括号放置于下一行的开头,所以:"
238 msgid ""
239 "\tint function(int x)\n"
240 "\t{\n"
241 "\t\tbody of function\n"
242 "\t}\n"
243 msgstr ""
244 "\tint function(int x)\n"
245 "\t{\n"
246 "\t\tbody of function\n"
247 "\t}\n"
249 msgid ""
250 "Heretic people all over the world have claimed that this inconsistency "
251 "is ...  well ...  inconsistent, but all right-thinking people know that (a) "
252 "K&R are _right_ and (b) K&R are right.  Besides, functions are special "
253 "anyway (you can't nest them in C)."
254 msgstr ""
255 "全世界的异端可能会抱怨这个不一致性是……呃……不一致的,不过所有思维健全的人都知"
256 "道(a)K&R是正确的,还有(b)K&R是正确的。此外,不管怎样函数都是特殊的(在C"
257 "语言中,函数是不能嵌套的)。"
259 msgid ""
260 "Note that the closing brace is empty on a line of its own, _except_ in the "
261 "cases where it is followed by a continuation of the same statement, ie a "
262 "\"while\" in a do-statement or an \"else\" in an if-statement, like this:"
263 msgstr ""
264 "注意结束大括号独自占据一行,除非它后面跟着同一个语句的剩余部分,也就是do语句"
265 "中的“while”或者if语句中的“else”,像这样:"
267 msgid ""
268 "\tdo {\n"
269 "\t\tbody of do-loop\n"
270 "\t} while (condition);\n"
271 msgstr ""
272 "\tdo {\n"
273 "\t\tbody of do-loop\n"
274 "\t} while (condition);\n"
276 msgid "and"
277 msgstr "和"
279 msgid ""
280 "\tif (x == y) {\n"
281 "\t\t..\n"
282 "\t} else if (x > y) {\n"
283 "\t\t...\n"
284 "\t} else {\n"
285 "\t\t....\n"
286 "\t}\n"
287 msgstr ""
288 "\tif (x == y) {\n"
289 "\t\t..\n"
290 "\t} else if (x > y) {\n"
291 "\t\t...\n"
292 "\t} else {\n"
293 "\t\t....\n"
294 "\t}\n"
296 msgid "Rationale: K&R."
297 msgstr "理由:K&R。"
299 msgid ""
300 "Also, note that this brace-placement also minimizes the number of empty (or "
301 "almost empty) lines, without any loss of readability.  Thus, as the supply "
302 "of new-lines on your screen is not a renewable resource (think 25-line "
303 "terminal screens here), you have more empty lines to put comments on."
304 msgstr ""
305 "也请注意这种大括号的放置方式也能使空(或者差不多空的)行的数量最小化,同时不"
306 "失可读性。因此,由于你的屏幕上的新行的供应不是可回收的资源(想想25行的终端屏"
307 "幕),你将会有更多的空行来放置注释。"
309 msgid "Do not unnecessarily use braces where a single statement will do."
310 msgstr "当只有一个单独的语句的时候,不必加大括号。"
312 msgid ""
313 "if (condition)\n"
314 "\taction();\n"
315 msgstr ""
316 "if (condition)\n"
317 "\taction();\n"
319 msgid ""
320 "This does not apply if one branch of a conditional statement is a single "
321 "statement. Use braces in both branches."
322 msgstr ""
323 "这点不适用于本身为某个条件语句的一个分支的单独语句。这时需要在两个分支里都使"
324 "用大括号。"
326 msgid ""
327 "if (condition) {\n"
328 "\tdo_this();\n"
329 "\tdo_that();\n"
330 "} else {\n"
331 "\totherwise();\n"
332 "}\n"
333 msgstr ""
334 "if (condition) {\n"
335 "\tdo_this();\n"
336 "\tdo_that();\n"
337 "} else {\n"
338 "\totherwise();\n"
339 "}\n"
341 msgid "\t\t3.1:  Spaces\n"
342 msgstr "\t\t3.1:空格\n"
344 msgid ""
345 "Linux kernel style for use of spaces depends (mostly) on function-versus-"
346 "keyword usage.  Use a space after (most) keywords.  The notable exceptions "
347 "are sizeof, typeof, alignof, and __attribute__, which look somewhat like "
348 "functions (and are usually used with parentheses in Linux, although they "
349 "are not required in the language, as in: \"sizeof info\" after \"struct "
350 "fileinfo info;\" is declared)."
351 msgstr ""
352 "Linux内核的空格使用风格(主要)取决于适用者是函数名还是关键字。在(大多数)关键字"
353 "后加一个空格。值得注意的例外是sizeof、typeof、alignof和__attribute__,这些关"
354 "键字某些程度上看起来更像函数(它们在Linux里也常常伴随小括号而使用,尽管在C语"
355 "言里这样的小括号不是必需的,就像“struct fileinfo info”声明过后的“sizeof "
356 "info”)。"
358 msgid ""
359 "So use a space after these keywords:\n"
360 "\tif, switch, case, for, do, while\n"
361 "but not with sizeof, typeof, alignof, or __attribute__.  E.g.,\n"
362 "\ts = sizeof(struct file);\n"
363 msgstr ""
364 "所以在这些关键字之后放一个空格:\n"
365 "\tif, switch, case, for, do, while\n"
366 "但是不要在sizeof、typeof、alignof或者 __attribute__这些关键字之后放空格。例如,\n"
367 "\ts = sizeof(struct file);\n"
369 msgid ""
370 "Do not add spaces around (inside) parenthesized expressions.  This example "
371 "is *bad*:"
372 msgstr "不要在小括号里的表达式两侧加空格。这是一个反例:"
374 msgid "\ts = sizeof( struct file );\n"
375 msgstr "\ts = sizeof( struct file );\n"
377 msgid ""
378 "When declaring pointer data or a function that returns a pointer type, the "
379 "preferred use of '*' is adjacent to the data name or function name and not "
380 "adjacent to the type name.  Examples:"
381 msgstr ""
382 "当声明指针类型或者返回指针类型的函数时,首选的“*”的使用方式是使之靠近变量名"
383 "或者函数名,而不是靠近类型名。例子:"
385 msgid ""
386 "\tchar *linux_banner;\n"
387 "\tunsigned long long memparse(char *ptr, char **retptr);\n"
388 "\tchar *match_strdup(substring_t *s);\n"
389 msgstr ""
390 "\tchar *linux_banner;\n"
391 "\tunsigned long long memparse(char *ptr, char **retptr);\n"
392 "\tchar *match_strdup(substring_t *s);\n"
394 msgid ""
395 "Use one space around (on each side of) most binary and ternary operators, "
396 "such as any of these:"
397 msgstr ""
398 "在大多数二元和三元操作符两侧使用一个空格,例如这些操作符中的任意一个:"
400 msgid "\t=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=  ?  :\n"
401 msgstr "\t=  +  -  <  >  *  /  %  |  &  ^  <=  >=  ==  !=  ?  :\n"
403 msgid ""
404 "but no space after unary operators:\n"
405 "\t&  *  +  -  ~  !  sizeof  typeof  alignof  __attribute__  defined\n"
406 msgstr ""
407 "但是一元操作符后不要加空格:\n"
408 "\t&  *  +  -  ~  !  sizeof  typeof  alignof  __attribute__  defined\n"
410 msgid ""
411 "no space before the postfix increment & decrement unary operators:\n"
412 "\t++  --\n"
413 msgstr ""
414 "后缀自加和自减一元操作符前不加空格:\n"
415 "\t++  --\n"
417 msgid ""
418 "no space after the prefix increment & decrement unary operators:\n"
419 "\t++  --\n"
420 msgstr ""
421 "前置自加和自减一元操作符后不加空格:\n"
422 "\t++  --\n"
424 msgid "and no space around the '.' and \"->\" structure member operators."
425 msgstr "“.”和“->”结构体成员操作符前后不加空格。"
427 msgid "\t\tChapter 4: Naming\n"
428 msgstr "\t\t第四章:命名\n"
430 msgid ""
431 "C is a Spartan language, and so should your naming be.  Unlike Modula-2 and "
432 "Pascal programmers, C programmers do not use cute names like "
433 "ThisVariableIsATemporaryCounter.  A C programmer would call that variable "
434 "\"tmp\", which is much easier to write, and not the least more difficult to "
435 "understand."
436 msgstr ""
437 "C是一个简朴的语言,你的命名也应该这样。和Modula-2和Pascal程序员不同,C程序员"
438 "不使用类似ThisVariableIsATemporaryCounter这样华丽的名字。C程序员会称那个变量"
439 "为“tmp”,这样写起来会更容易,而且至少不会令其难于理解。"
441 msgid ""
442 "HOWEVER, while mixed-case names are frowned upon, descriptive names for "
443 "global variables are a must.  To call a global function \"foo\" is a "
444 "shooting offense."
445 msgstr ""
446 "不过,虽然混用大小写的名字是不提倡使用的,但是全局变量还是需要一个具描述性的"
447 "名字。称一个全局函数为“foo”是一个难以饶恕的错误。"
449 msgid ""
450 "GLOBAL variables (to be used only if you _really_ need them) need to have "
451 "descriptive names, as do global functions.  If you have a function that "
452 "counts the number of active users, you should call that \"count_active_users"
453 "()\" or similar, you should _not_ call it \"cntusr()\"."
454 msgstr ""
455 "全局变量(只有当你真正需要它们的时候再用它)需要有一个具描述性的名字,就像全"
456 "局函数。如果你有一个可以计算活动用户数量的函数,你应该叫"
457 "它“count_active_users()”或者类似的名字,你不应该叫它“cntuser()”。"
459 msgid ""
460 "Encoding the type of a function into the name (so-called Hungarian "
461 "notation) is brain damaged - the compiler knows the types anyway and can "
462 "check those, and it only confuses the programmer.  No wonder MicroSoft "
463 "makes buggy programs."
464 msgstr ""
465 "在函数名中包含函数类型(所谓的匈牙利命名法)是脑子出了问题——编译器知道那些类"
466 "型而且能够检查那些类型,这样做只能把程序员弄糊涂了。难怪微软总是制造出有问题"
467 "的程序。"
469 msgid ""
470 "LOCAL variable names should be short, and to the point.  If you have some "
471 "random integer loop counter, it should probably be called \"i\".  Calling "
472 "it \"loop_counter\" is non-productive, if there is no chance of it being "
473 "mis-understood.  Similarly, \"tmp\" can be just about any type of variable "
474 "that is used to hold a temporary value."
475 msgstr ""
476 "本地变量名应该简短,而且能够表达相关的含义。如果你有一些随机的整数型的循环计"
477 "数器,它应该被称为“i”。叫它“loop_counter”并无益处,如果它没有可能被误解的"
478 "话。类似的,“tmp”可以用来称呼任意类型的临时变量。"
480 msgid ""
481 "If you are afraid to mix up your local variable names, you have another "
482 "problem, which is called the function-growth-hormone-imbalance syndrome.  "
483 "See chapter 6 (Functions)."
484 msgstr ""
485 "如果你怕混淆了你的本地变量名,你就遇到另一个问题了,叫做函数增长荷尔蒙失衡综"
486 "合症。请看第六章(函数)。"
488 msgid "\t\tChapter 5: Typedefs\n"
489 msgstr "\t\t第五章:Typedef\n"
491 msgid "Please don't use things like \"vps_t\"."
492 msgstr "不要使用类似“vps_t”之类的东西。"
494 msgid ""
495 "It's a _mistake_ to use typedef for structures and pointers. When you see a"
496 msgstr "对结构体和指针使用typedef是一个错误。当你在代码里看到:"
498 msgid "\tvps_t a;\n"
499 msgstr "\tvps_t a;\n"
501 msgid "in the source, what does it mean?"
502 msgstr "这代表什么意思呢?"
504 msgid "In contrast, if it says"
505 msgstr "相反,如果是这样"
507 msgid "\tstruct virtual_container *a;\n"
508 msgstr "\tstruct virtual_container *a;\n"
510 msgid "you can actually tell what \"a\" is."
511 msgstr "你就知道“a”是什么了。"
513 msgid ""
514 "Lots of people think that typedefs \"help readability\". Not so. They are "
515 "useful only for:"
516 msgstr ""
517 "很多人认为typedef“能提高可读性”。实际不是这样的。它们只在下列情况下有用:"
519 msgid ""
520 " (a) totally opaque objects (where the typedef is actively used to _hide_\n"
521 "     what the object is).\n"
522 msgstr " (a) 完全不透明的对象(这种情况下要主动使用typedef来隐藏这个对象实际上是什么)。\n"
524 msgid ""
525 "     Example: \"pte_t\" etc. opaque objects that you can only access using\n"
526 "     the proper accessor functions.\n"
527 msgstr "     例如:“pte_t”等不透明对象,你只能用合适的访问函数来访问它们。\n"
529 msgid ""
530 "     NOTE! Opaqueness and \"accessor functions\" are not good in themselves.\n"
531 "     The reason we have them for things like pte_t etc. is that there\n"
532 "     really is absolutely _zero_ portably accessible information there.\n"
533 msgstr "     注意!不透明性和“访问函数本身”是不好的。我们使用pte_t等类型的原因在于真的是完全没有任何共用的可访问信息。\n"
535 msgid ""
536 " (b) Clear integer types, where the abstraction _helps_ avoid confusion\n"
537 "     whether it is \"int\" or \"long\".\n"
538 msgstr " (b) 清除整数类型,如此,这层抽象就可以帮助消除到底是“int”还是“long”的混淆。\n"
540 msgid ""
541 "     u8/u16/u32 are perfectly fine typedefs, although they fit into\n"
542 "     category (d) better than here.\n"
543 msgstr "     u8/u16/u32是完全没有问题的typedef,不过它们更符合类别(d)而不是这里。\n"
545 msgid ""
546 "     NOTE! Again - there needs to be a _reason_ for this. If something is\n"
547 "     \"unsigned long\", then there's no reason to do\n"
548 msgstr "     再次注意!要这样做,必须事出有因。如果某个变量是“unsigned long“,那么没有必要\n"
550 msgid "\ttypedef unsigned long myflags_t;\n"
551 msgstr "\ttypedef unsigned long myflags_t;\n"
553 msgid ""
554 "     but if there is a clear reason for why it under certain circumstances\n"
555 "     might be an \"unsigned int\" and under other configurations might be\n"
556 "     \"unsigned long\", then by all means go ahead and use a typedef.\n"
557 msgstr "     不过如果有一个明确的原因,比如它在某种情况下可能会是一个“unsigned int”而在其他情况下可能为“unsigned long”,那么就不要犹豫,请务必使用typedef。\n"
559 msgid ""
560 " (c) when you use sparse to literally create a _new_ type for\n"
561 "     type-checking.\n"
562 msgstr " (c) 当你使用sparse按字面的创建一个新类型来做类型检查的时候。\n"
564 msgid ""
565 " (d) New types which are identical to standard C99 types, in certain\n"
566 "     exceptional circumstances.\n"
567 msgstr " (d) 和标准C99类型相同的类型,在某些例外的情况下。\n"
569 msgid ""
570 "     Although it would only take a short amount of time for the eyes and\n"
571 "     brain to become accustomed to the standard types like 'uint32_t',\n"
572 "     some people object to their use anyway.\n"
573 msgstr "     虽然让眼睛和脑筋来适应新的标准类型比如“uint32_t”不需要花很多时间,可以有些人仍然拒绝使用它们。\n"
575 msgid ""
576 "     Therefore, the Linux-specific 'u8/u16/u32/u64' types and their\n"
577 "     signed equivalents which are identical to standard types are\n"
578 "     permitted -- although they are not mandatory in new code of your\n"
579 "     own.\n"
580 msgstr "     因此,Linux特有的等同于标准类型的“u8/u16/u32/u64”类型和它们的有符号类型是被允许的——尽管在你自己的新代码中,它们不是强制要求要使用的。\n"
582 msgid ""
583 "     When editing existing code which already uses one or the other set\n"
584 "     of types, you should conform to the existing choices in that code.\n"
585 msgstr "     当编辑已经使用了某个类型集的已有代码时,你应该遵循那些代码中已经做出的选择。\n"
587 msgid " (e) Types safe for use in userspace.\n"
588 msgstr " (e) 可以在用户空间安全使用的类型。\n"
590 msgid ""
591 "     In certain structures which are visible to userspace, we cannot\n"
592 "     require C99 types and cannot use the 'u32' form above. Thus, we\n"
593 "     use __u32 and similar types in all structures which are shared\n"
594 "     with userspace.\n"
595 msgstr "     在某些用户空间可见的结构体里,我们不能要求C99类型而且不能用上面提到的“u32”类型。因此,我们在与用户空间共享的所有结构体中使用__u32和类似的类型。\n"
597 msgid ""
598 "Maybe there are other cases too, but the rule should basically be to NEVER "
599 "EVER use a typedef unless you can clearly match one of those rules."
600 msgstr ""
601 "可能还有其他的情况,不过基本的规则是永远不要使用typedef,除非你可以明确的应"
602 "用上述某个规则中的一个。"
604 msgid ""
605 "In general, a pointer, or a struct that has elements that can reasonably be "
606 "directly accessed should _never_ be a typedef."
607 msgstr ""
608 "总的来说,如果一个指针或者一个结构体里的元素可以合理的被直接访问到,那么它们"
609 "就不应该是一个typedef。"
611 msgid "\t\tChapter 6: Functions\n"
612 msgstr "\t\t第六章:函数\n"
614 msgid ""
615 "Functions should be short and sweet, and do just one thing.  They should "
616 "fit on one or two screenfuls of text (the ISO/ANSI screen size is 80x24, as "
617 "we all know), and do one thing and do that well."
618 msgstr ""
619 "函数应该简短而漂亮,并且只完成一件事情。函数应该可以一屏或者两屏显示完(我们"
620 "都知道ISO/ANSI屏幕大小是80x24),只做一件事情,而且把它做好。"
622 msgid ""
623 "The maximum length of a function is inversely proportional to the "
624 "complexity and indentation level of that function.  So, if you have a "
625 "conceptually simple function that is just one long (but simple)  case-"
626 "statement, where you have to do lots of small things for a lot of different "
627 "cases, it's OK to have a longer function."
628 msgstr ""
629 "一个函数的最大长度是和该函数的复杂度和缩进级数成反比的。所以,如果你有一个理"
630 "论上很简单的只有一个很长(但是简单)的case语句的函数,而且你需要在每个case里"
631 "做很多很小的事情,这样的函数尽管很长,但也是可以的。"
633 msgid ""
634 "However, if you have a complex function, and you suspect that a less-than-"
635 "gifted first-year high-school student might not even understand what the "
636 "function is all about, you should adhere to the maximum limits all the more "
637 "closely.  Use helper functions with descriptive names (you can ask the "
638 "compiler to in-line them if you think it's performance-critical, and it "
639 "will probably do a better job of it than you would have done)."
640 msgstr ""
641 "不过,如果你有一个复杂的函数,而且你怀疑一个天分不是很高的高中一年级学生可能"
642 "甚至搞不清楚这个函数的目的,你应该更严格的遵守最大限制。使用帮助函数,并为之"
643 "取个具描述性的名字(你可以让编译器把它们直接置于行间如果你觉得它们对于程序的"
644 "表现有决定性影响的话,而且它完成这项任务会比你完成的更好。)"
646 msgid ""
647 "Another measure of the function is the number of local variables.  They "
648 "shouldn't exceed 5-10, or you're doing something wrong.  Re-think the "
649 "function, and split it into smaller pieces.  A human brain can generally "
650 "easily keep track of about 7 different things, anything more and it gets "
651 "confused.  You know you're brilliant, but maybe you'd like to understand "
652 "what you did 2 weeks from now."
653 msgstr ""
654 "函数的另外一个衡量标准是本地变量的数量。此数量不应超过5-10个,否则你的函数"
655 "就有问题了。重新考虑一下你的函数,把它分拆成更小的函数。人的大脑一般可以轻松"
656 "的同时跟踪7个不同的事物,如果再增多的话,就会糊涂了。你知道你聪颖过人,不过"
657 "你可能会想了解你2个星期前做过的事情。"
659 msgid ""
660 "In source files, separate functions with one blank line.  If the function "
661 "is exported, the EXPORT* macro for it should follow immediately after the "
662 "closing function brace line.  E.g.:"
663 msgstr ""
664 "在源文件里,使用空行隔开不同的函数。如果该函数需要被导出,它的EXPORT*宏应该"
665 "紧贴在它的结束大括号之下。比如:"
667 msgid ""
668 "int system_is_up(void)\n"
669 "{\n"
670 "\treturn system_state == SYSTEM_RUNNING;\n"
671 "}\n"
672 "EXPORT_SYMBOL(system_is_up);\n"
673 msgstr ""
674 "int system_is_up(void)\n"
675 "{\n"
676 "\treturn system_state == SYSTEM_RUNNING;\n"
677 "}\n"
678 "EXPORT_SYMBOL(system_is_up);\n"
680 msgid ""
681 "In function prototypes, include parameter names with their data types.  "
682 "Although this is not required by the C language, it is preferred in Linux "
683 "because it is a simple way to add valuable information for the reader."
684 msgstr ""
685 "在函数原型中,包含函数名和它们的数据类型。虽然C语言里没有这样的要求,在Linux"
686 "里这是提倡的做法,因为这样可以很简单的给读者提供更多的有价值的信息。"
688 msgid "\t\tChapter 7: Centralized exiting of functions\n"
689 msgstr "\t\t第七章:集中的函数退出途径\n"
691 msgid ""
692 "Albeit deprecated by some people, the equivalent of the goto statement is "
693 "used frequently by compilers in form of the unconditional jump instruction."
694 msgstr ""
695 "虽然被某些人声称已经过时,但是goto语句的等价物还是经常被编译器所使用,具体形"
696 "式是无条件跳转指令。"
698 msgid ""
699 "The goto statement comes in handy when a function exits from multiple "
700 "locations and some common work such as cleanup has to be done."
701 msgstr ""
702 "当一个函数从多个位置退出并且需要做一些通用的清洁工作的时候,goto的好处就显现"
703 "出来了。"
705 msgid "The rationale is:"
706 msgstr "理由是:"
708 msgid "unconditional statements are easier to understand and follow"
709 msgstr "无条件语句容易理解和跟踪"
711 msgid "nesting is reduced"
712 msgstr "嵌套程度减小"
714 msgid ""
715 "- errors by not updating individual exit points when making\n"
716 "    modifications are prevented\n"
717 "- saves the compiler work to optimize redundant code away ;)\n"
718 msgstr ""
719 "- 可以避免由于修改时忘记更新某个单独的退出点而导致的错误\n"
720 "- 减轻了编译器的工作,无需删除冗余代码;)\n"
722 msgid ""
723 "int fun(int a)\n"
724 "{\n"
725 "\tint result = 0;\n"
726 "\tchar *buffer = kmalloc(SIZE);\n"
727 msgstr ""
728 "int fun(int a)\n"
729 "{\n"
730 "\tint result = 0;\n"
731 "\tchar *buffer = kmalloc(SIZE);\n"
733 msgid ""
734 "\tif (buffer == NULL)\n"
735 "\t\treturn -ENOMEM;\n"
736 msgstr ""
737 "\tif (buffer == NULL)\n"
738 "\t\treturn -ENOMEM;\n"
740 msgid ""
741 "\tif (condition1) {\n"
742 "\t\twhile (loop1) {\n"
743 "\t\t\t...\n"
744 "\t\t}\n"
745 "\t\tresult = 1;\n"
746 "\t\tgoto out;\n"
747 "\t}\n"
748 "\t...\n"
749 "out:\n"
750 "\tkfree(buffer);\n"
751 "\treturn result;\n"
752 "}\n"
753 msgstr ""
754 "\tif (condition1) {\n"
755 "\t\twhile (loop1) {\n"
756 "\t\t\t...\n"
757 "\t\t}\n"
758 "\t\tresult = 1;\n"
759 "\t\tgoto out;\n"
760 "\t}\n"
761 "\t...\n"
762 "out:\n"
763 "\tkfree(buffer);\n"
764 "\treturn result;\n"
765 "}\n"
767 msgid "\t\tChapter 8: Commenting\n"
768 msgstr "\t\t第八章:注释\n"
770 msgid ""
771 "Comments are good, but there is also a danger of over-commenting.  NEVER "
772 "try to explain HOW your code works in a comment: it's much better to write "
773 "the code so that the _working_ is obvious, and it's a waste of time to "
774 "explain badly written code."
775 msgstr ""
776 "注释是好的,不过有过度注释的危险。永远不要在注释里解释你的代码是如何运作的:"
777 "更好的做法是让别人一看你的代码就可以明白,解释写的很差的代码是浪费时间。"
779 msgid ""
780 "Generally, you want your comments to tell WHAT your code does, not HOW.  "
781 "Also, try to avoid putting comments inside a function body: if the function "
782 "is so complex that you need to separately comment parts of it, you should "
783 "probably go back to chapter 6 for a while.  You can make small comments to "
784 "note or warn about something particularly clever (or ugly), but try to "
785 "avoid excess.  Instead, put the comments at the head of the function, "
786 "telling people what it does, and possibly WHY it does it."
787 msgstr ""
788 "一般的,你想要你的注释告诉别人你的代码做了什么,而不是怎么做的。也请你不要把"
789 "注释放在一个函数体内部:如果函数复杂到你需要独立的注释其中的一部分,你很可能"
790 "需要回到第六章看一看。你可以做一些小注释来注明或警告某些很聪明(或者槽糕)的"
791 "做法,但不要加太多。你应该做的,是把注释放在函数的头部,告诉人们它做了什么,"
792 "也可以加上它做这些事情的原因。"
794 msgid ""
795 "When commenting the kernel API functions, please use the kernel-doc "
796 "format.  See the files Documentation/kernel-doc-nano-HOWTO.txt and scripts/"
797 "kernel-doc for details."
798 msgstr ""
799 "当注释内核API函数时,请使用kernel-doc格式。请看Documentation/kernel-doc-"
800 "nano-HOWTO.txt和scripts/kernel-doc以获得详细信息。"
802 msgid ""
803 "Linux style for comments is the C89 \"/* ... */\" style.  Don't use C99-"
804 "style \"// ...\" comments."
805 msgstr "Linux的注释风格是C89“/* ... */”风格。不要使用C99风格“// ...”注释。"
807 msgid "The preferred style for long (multi-line) comments is:"
808 msgstr "首选的长(多行)注释的风格是:"
810 msgid ""
811 "\t/*\n"
812 "\t * This is the preferred style for multi-line\n"
813 "\t * comments in the Linux kernel source code.\n"
814 "\t * Please use it consistently.\n"
815 "\t *\n"
816 "\t * Description:  A column of asterisks on the left side,\n"
817 "\t * with beginning and ending almost-blank lines.\n"
818 "\t */\n"
819 msgstr ""
820 "\t/*\n"
821 "\t * This is the preferred style for multi-line\n"
822 "\t * comments in the Linux kernel source code.\n"
823 "\t * Please use it consistently.\n"
824 "\t *\n"
825 "\t * Description:  A column of asterisks on the left side,\n"
826 "\t * with beginning and ending almost-blank lines.\n"
827 "\t */\n"
829 msgid ""
830 "It's also important to comment data, whether they are basic types or "
831 "derived types.  To this end, use just one data declaration per line (no "
832 "commas for multiple data declarations).  This leaves you room for a small "
833 "comment on each item, explaining its use."
834 msgstr ""
835 "注释数据也是很重要的,不管是基本类型还是衍生类型。为了方便实现这一点,每一行"
836 "应只声明一个数据(不要使用逗号来一次声明多个数据)。这样你就有空间来为每个数"
837 "据写一段小注释来解释它们的用途了。"
839 msgid "\t\tChapter 9: You've made a mess of it\n"
840 msgstr "\t\t第九章:你已经把事情弄糟了\n"
842 msgid ""
843 "That's OK, we all do.  You've probably been told by your long-time Unix "
844 "user helper that \"GNU emacs\" automatically formats the C sources for you, "
845 "and you've noticed that yes, it does do that, but the defaults it uses are "
846 "less than desirable (in fact, they are worse than random typing - an "
847 "infinite number of monkeys typing into GNU emacs would never make a good "
848 "program)."
849 msgstr ""
850 "这没什么,我们都是这样。可能你的使用了很长时间Unix的朋友已经告诉你“GNU "
851 "emacs”能自动帮你格式化C源代码,而且你也注意到了,确实是这样,不过它所使用的"
852 "默认值和我们想要的相去甚远(实际上,甚至比随机打的还要差——无数个猴子在GNU "
853 "emacs里打字永远不会创造出一个好程序)(译注:请参考Infinite Monkey Theorem)"
855 msgid ""
856 "So, you can either get rid of GNU emacs, or change it to use saner values.  "
857 "To do the latter, you can stick the following in your .emacs file:"
858 msgstr ""
859 "所以你要么放弃GNU emacs,要么改变它让它使用更合理的设定。要采用后一个方案,"
860 "你可以把下面这段粘贴到你的.emacs文件里。"
862 msgid ""
863 "(defun linux-c-mode ()\n"
864 "  \"C mode with adjusted defaults for use with the Linux kernel.\"\n"
865 "  (interactive)\n"
866 "  (c-mode)\n"
867 "  (c-set-style \"K&R\")\n"
868 "  (setq tab-width 8)\n"
869 "  (setq indent-tabs-mode t)\n"
870 "  (setq c-basic-offset 8))\n"
871 msgstr ""
872 "(defun linux-c-mode ()\n"
873 "  \"C mode with adjusted defaults for use with the Linux kernel.\"\n"
874 "  (interactive)\n"
875 "  (c-mode)\n"
876 "  (c-set-style \"K&R\")\n"
877 "  (setq tab-width 8)\n"
878 "  (setq indent-tabs-mode t)\n"
879 "  (setq c-basic-offset 8))\n"
881 msgid ""
882 "This will define the M-x linux-c-mode command.  When hacking on a module, "
883 "if you put the string -*- linux-c -*- somewhere on the first two lines, "
884 "this mode will be automatically invoked. Also, you may want to add"
885 msgstr ""
886 "这样就定义了M-x linux-c-mode命令。当你hack一个模块的时候,如果你把字符串-*- "
887 "linux-c -*-放在头两行的某个位置,这个模式将会被自动调用。如果你希望在你修改/"
888 "usr/src/linux里的文件时魔术般自动打开linux-c-mode的话,你也可能需要添加"
890 msgid ""
891 "(setq auto-mode-alist (cons '(\"/usr/src/linux.*/.*\\\\.[ch]$\" . linux-c-mode)\n"
892 "\t\t\tauto-mode-alist))\n"
893 msgstr ""
894 "(setq auto-mode-alist (cons '(\"/usr/src/linux.*/.*\\\\.[ch]$\" . linux-c-mode)\n"
895 "\t\t\tauto-mode-alist))\n"
897 msgid ""
898 "to your .emacs file if you want to have linux-c-mode switched on "
899 "automagically when you edit source files under /usr/src/linux."
900 msgstr "到你的.emacs文件里。"
902 msgid ""
903 "But even if you fail in getting emacs to do sane formatting, not everything "
904 "is lost: use \"indent\"."
905 msgstr ""
906 "不过就算你尝试让emacs正确的格式化代码失败了,也并不意味着你失去了一切:还可"
907 "以用“indent”。"
909 msgid ""
910 "Now, again, GNU indent has the same brain-dead settings that GNU emacs has, "
911 "which is why you need to give it a few command line options.  However, "
912 "that's not too bad, because even the makers of GNU indent recognize the "
913 "authority of K&R (the GNU people aren't evil, they are just severely "
914 "misguided in this matter), so you just give indent the options \"-kr -i8"
915 "\" (stands for \"K&R, 8 character indents\"), or use \"scripts/Lindent\", "
916 "which indents in the latest style."
917 msgstr ""
918 "不过,GNU indent也有和GNU emacs一样有问题的设定,所以你需要给它一些命令选"
919 "项。不过,这还不算太糟糕,因为就算是GNU indent的作者也认同K&R的权威性(GNU的"
920 "人并不是坏人,他们只是在这个问题上被严重的误导了),所以你只要给indent指定选"
921 "项“-kr -i8”(代表“K&R,8个字符缩进”),或者使用“scripts/Lindent”,这样就可以"
922 "以最时髦的方式缩进源代码。"
924 msgid ""
925 "\"indent\" has a lot of options, and especially when it comes to comment re-"
926 "formatting you may want to take a look at the man page.  But remember: "
927 "\"indent\" is not a fix for bad programming."
928 msgstr ""
929 "“indent”有很多选项,特别是重新格式化注释的时候,你可能需要看一下它的手册页。"
930 "不过记住:“indent”不能修正坏的编程习惯。"
932 msgid "\t\tChapter 10: Kconfig configuration files\n"
933 msgstr "\t\t第十章:Kconfig配置文件\n"
935 msgid ""
936 "For all of the Kconfig* configuration files throughout the source tree, the "
937 "indentation is somewhat different.  Lines under a \"config\" definition are "
938 "indented with one tab, while help text is indented an additional two "
939 "spaces.  Example:"
940 msgstr ""
941 "对于遍布源码树的所有Kconfig*配置文件来说,它们缩进方式与C代码相比有所不同。"
942 "紧挨在“config”定义下面的行缩进一个制表符,帮助信息则再多缩进2个空格。比如:"
944 msgid ""
945 "config AUDIT\n"
946 "\tbool \"Auditing support\"\n"
947 "\tdepends on NET\n"
948 "\thelp\n"
949 "\t  Enable auditing infrastructure that can be used with another\n"
950 "\t  kernel subsystem, such as SELinux (which requires this for\n"
951 "\t  logging of avc messages output).  Does not do system-call\n"
952 "\t  auditing without CONFIG_AUDITSYSCALL.\n"
953 msgstr ""
954 "config AUDIT\n"
955 "\tbool \"Auditing support\"\n"
956 "\tdepends on NET\n"
957 "\thelp\n"
958 "\t  Enable auditing infrastructure that can be used with another\n"
959 "\t  kernel subsystem, such as SELinux (which requires this for\n"
960 "\t  logging of avc messages output).  Does not do system-call\n"
961 "\t  auditing without CONFIG_AUDITSYSCALL.\n"
963 msgid ""
964 "Features that might still be considered unstable should be defined as "
965 "dependent on \"EXPERIMENTAL\":"
966 msgstr "仍然被认为不够稳定的功能应该被定义为依赖于“EXPERIMENTAL”:"
968 msgid ""
969 "config SLUB\n"
970 "\tdepends on EXPERIMENTAL && !ARCH_USES_SLAB_PAGE_STRUCT\n"
971 "\tbool \"SLUB (Unqueued Allocator)\"\n"
972 "\t...\n"
973 msgstr ""
974 "config SLUB\n"
975 "\tdepends on EXPERIMENTAL && !ARCH_USES_SLAB_PAGE_STRUCT\n"
976 "\tbool \"SLUB (Unqueued Allocator)\"\n"
977 "\t...\n"
979 msgid ""
980 "while seriously dangerous features (such as write support for certain "
981 "filesystems) should advertise this prominently in their prompt string:"
982 msgstr ""
983 "而那些危险的功能(比如某些文件系统的写支持)应该在它们的提示字符串里显著的声"
984 "明这一点:"
986 msgid ""
987 "config ADFS_FS_RW\n"
988 "\tbool \"ADFS write support (DANGEROUS)\"\n"
989 "\tdepends on ADFS_FS\n"
990 "\t...\n"
991 msgstr ""
992 "config ADFS_FS_RW\n"
993 "\tbool \"ADFS write support (DANGEROUS)\"\n"
994 "\tdepends on ADFS_FS\n"
995 "\t...\n"
997 msgid ""
998 "For full documentation on the configuration files, see the file "
999 "Documentation/kbuild/kconfig-language.txt."
1000 msgstr ""
1001 "要查看配置文件的完整文档,请看Documentation/kbuild/kconfig-language.txt。"
1003 msgid "\t\tChapter 11: Data structures\n"
1004 msgstr "\t\t第十一章:数据结构\n"
1006 msgid ""
1007 "Data structures that have visibility outside the single-threaded "
1008 "environment they are created and destroyed in should always have reference "
1009 "counts.  In the kernel, garbage collection doesn't exist (and outside the "
1010 "kernel garbage collection is slow and inefficient), which means that you "
1011 "absolutely _have_ to reference count all your uses."
1012 msgstr ""
1013 "如果一个数据结构,在创建和销毁它的单线执行环境之外可见,那么它必须要有一个引"
1014 "用计数器。内核里没有垃圾收集(并且内核之外的垃圾收集慢且效率低下),这意味着"
1015 "你绝对需要记录你对这种数据结构的使用情况。"
1017 msgid ""
1018 "Reference counting means that you can avoid locking, and allows multiple "
1019 "users to have access to the data structure in parallel - and not having to "
1020 "worry about the structure suddenly going away from under them just because "
1021 "they slept or did something else for a while."
1022 msgstr ""
1023 "引用计数意味着你能够避免上锁,并且允许多个用户并行访问这个数据结构——而不需要"
1024 "担心这个数据结构仅仅因为暂时不被使用就消失了,那些用户可能不过是沉睡了一阵或"
1025 "者做了一些其他事情而以。"
1027 msgid ""
1028 "Note that locking is _not_ a replacement for reference counting.  Locking "
1029 "is used to keep data structures coherent, while reference counting is a "
1030 "memory management technique.  Usually both are needed, and they are not to "
1031 "be confused with each other."
1032 msgstr ""
1033 "注意上锁不能取代引用计数。上锁是为了保持数据结构的一致性,而引用计数是一个内"
1034 "存管理技巧。通常二者都需要,不要把两个搞混了。"
1036 msgid ""
1037 "Many data structures can indeed have two levels of reference counting, when "
1038 "there are users of different \"classes\".  The subclass count counts the "
1039 "number of subclass users, and decrements the global count just once when "
1040 "the subclass count goes to zero."
1041 msgstr ""
1042 "很多数据结构实际上有2级引用计数,它们通常有不同“类”的用户。子类计数器统计子"
1043 "类用户的数量,每当子类计数器减至零时,全局计数器减一。"
1045 msgid ""
1046 "Examples of this kind of \"multi-level-reference-counting\" can be found in "
1047 "memory management (\"struct mm_struct\": mm_users and mm_count), and in "
1048 "filesystem code (\"struct super_block\": s_count and s_active)."
1049 msgstr ""
1050 "这种“多级引用计数”的例子可以在内存管理(“struct mm_struct”:mm_users和"
1051 "mm_count)和文件系统(“struct super_block”:s_count和s_active)。"
1053 msgid ""
1054 "Remember: if another thread can find your data structure, and you don't "
1055 "have a reference count on it, you almost certainly have a bug."
1056 msgstr ""
1057 "记住:如果另一个执行线索可以找到你的数据结构,但是这个数据结构没有引用计数"
1058 "器,这里几乎肯定是一个bug。"
1060 msgid "\t\tChapter 12: Macros, Enums and RTL\n"
1061 msgstr "\t\t第十二章:宏,列举和RTL\n"
1063 msgid ""
1064 "Names of macros defining constants and labels in enums are capitalized."
1065 msgstr "定义常量和列举里的标签的宏的名字需要大写。"
1067 msgid "#define CONSTANT 0x12345"
1068 msgstr "#define CONSTANT 0x12345"
1070 msgid "Enums are preferred when defining several related constants."
1071 msgstr "在定义几个相关的常量时,最好用列举。"
1073 msgid ""
1074 "CAPITALIZED macro names are appreciated but macros resembling functions may "
1075 "be named in lower case."
1076 msgstr "宏的名字请用大写字母,不过形如函数的宏的名字可以用小写字母。"
1078 msgid ""
1079 "Generally, inline functions are preferable to macros resembling functions."
1080 msgstr "一般的,如果能写成内联函数就不要写成像函数的宏。"
1082 msgid ""
1083 "Macros with multiple statements should be enclosed in a do - while block:"
1084 msgstr "含有多个语句的宏应该被包含在一个do-while代码块里:"
1086 msgid ""
1087 "#define macrofun(a, b, c) \t\t\t\\\n"
1088 "\tdo {\t\t\t\t\t\\\n"
1089 "\t\tif (a == 5)\t\t\t\\\n"
1090 "\t\t\tdo_this(b, c);\t\t\\\n"
1091 "\t} while (0)\n"
1092 msgstr ""
1093 "#define macrofun(a, b, c) \t\t\t\\\n"
1094 "\tdo {\t\t\t\t\t\\\n"
1095 "\t\tif (a == 5)\t\t\t\\\n"
1096 "\t\t\tdo_this(b, c);\t\t\\\n"
1097 "\t} while (0)\n"
1099 msgid "Things to avoid when using macros:"
1100 msgstr "使用宏的时候应避免的事情:"
1102 msgid "macros that affect control flow:"
1103 msgstr "影响控制流程的宏:"
1105 msgid ""
1106 "#define FOO(x)\t\t\t\t\t\\\n"
1107 "\tdo {\t\t\t\t\t\\\n"
1108 "\t\tif (blah(x) < 0)\t\t\\\n"
1109 "\t\t\treturn -EBUGGERED;\t\\\n"
1110 "\t} while(0)\n"
1111 msgstr ""
1112 "#define FOO(x)\t\t\t\t\t\\\n"
1113 "\tdo {\t\t\t\t\t\\\n"
1114 "\t\tif (blah(x) < 0)\t\t\\\n"
1115 "\t\t\treturn -EBUGGERED;\t\\\n"
1116 "\t} while(0)\n"
1118 msgid ""
1119 "is a _very_ bad idea.  It looks like a function call but exits the \"calling"
1120 "\" function; don't break the internal parsers of those who will read the "
1121 "code."
1122 msgstr ""
1123 "非常不好。它看起来像一个函数,不过却能导致“调用”它的函数退出;不要打乱将要读"
1124 "代码的人的内部语法分析器。"
1126 msgid "macros that depend on having a local variable with a magic name:"
1127 msgstr "依赖于一个固定名字的本地变量的宏:"
1129 msgid "#define FOO(val) bar(index, val)"
1130 msgstr "#define FOO(val) bar(index, val)"
1132 msgid ""
1133 "might look like a good thing, but it's confusing as hell when one reads the "
1134 "code and it's prone to breakage from seemingly innocent changes."
1135 msgstr ""
1136 "可能看起来像是个不错的东西,不过它非常容易把读代码的人搞糊涂,而且容易导致看"
1137 "起来不相关的改动带来错误。"
1139 msgid ""
1140 "3) macros with arguments that are used as l-values: FOO(x) = y; will\n"
1141 "bite you if somebody e.g. turns FOO into an inline function.\n"
1142 msgstr "3) 作为左值的带参数的宏: FOO(x) = y;如果有人把FOO变成一个内联函数的话,这种用法就会出错了。\n"
1144 msgid ""
1145 "4) forgetting about precedence: macros defining constants using expressions\n"
1146 "must enclose the expression in parentheses. Beware of similar issues with\n"
1147 "macros using parameters.\n"
1148 msgstr "4) 忘记了优先级:使用表达式定义常量的宏必须将表达式置于一对小括号之内。带参数的宏也要注意此类问题。\n"
1150 msgid "#define CONSTANT 0x4000 #define CONSTEXP (CONSTANT | 3)"
1151 msgstr "#define CONSTANT 0x4000 #define CONSTEXP (CONSTANT | 3)"
1153 msgid ""
1154 "The cpp manual deals with macros exhaustively. The gcc internals manual "
1155 "also covers RTL which is used frequently with assembly language in the "
1156 "kernel."
1157 msgstr ""
1158 "cpp手册对宏的讲解很详细。Gcc internals手册也详细讲解了RTL(译注:register "
1159 "transfer language),内核里的汇编语言经常用到它。"
1161 msgid "\t\tChapter 13: Printing kernel messages\n"
1162 msgstr "\t\t第十三章:打印内核消息\n"
1164 msgid ""
1165 "Kernel developers like to be seen as literate. Do mind the spelling of "
1166 "kernel messages to make a good impression. Do not use crippled words like "
1167 "\"dont\" and use \"do not\" or \"don't\" instead."
1168 msgstr ""
1169 "内核开发者应该是受过良好教育的。请一定注意内核信息的拼写,以给人以好的印象。"
1170 "不要用不规范的单词比如“dont”,而要用“do not”或者“don't”。"
1172 msgid "Kernel messages do not have to be terminated with a period."
1173 msgstr "内核信息不必以句号(译注:英文句号,即点)结束。"
1175 msgid ""
1176 "Printing numbers in parentheses (%d) adds no value and should be avoided."
1177 msgstr "在小括号里打印数字(%d)没有任何价值,应该避免这样做。"
1179 msgid "\t\tChapter 14: Allocating memory\n"
1180 msgstr "\t\t第十四章:分配内存\n"
1182 msgid ""
1183 "The kernel provides the following general purpose memory allocators: kmalloc"
1184 "(), kzalloc(), kcalloc(), and vmalloc().  Please refer to the API "
1185 "documentation for further information about them."
1186 msgstr ""
1187 "内核提供了下面的一般用途的内存分配函数:kmalloc(),kzalloc(),kcalloc()和"
1188 "vmalloc()。请参考API文档以获取有关它们的详细信息。"
1190 msgid "The preferred form for passing a size of a struct is the following:"
1191 msgstr "首选的传递结构体大小的形式是这样的:"
1193 msgid "\tp = kmalloc(sizeof(*p), ...);\n"
1194 msgstr "\tp = kmalloc(sizeof(*p), ...);\n"
1196 msgid ""
1197 "The alternative form where struct name is spelled out hurts readability and "
1198 "introduces an opportunity for a bug when the pointer variable type is "
1199 "changed but the corresponding sizeof that is passed to a memory allocator "
1200 "is not."
1201 msgstr ""
1202 "另外一种传递方式中,sizeof的操作数是结构体的名字,这样会降低可读性,并且可能"
1203 "会引入bug。有可能指针变量类型被改变时,而对应的传递给内存分配函数的sizeof的"
1204 "结果不变。"
1206 msgid ""
1207 "Casting the return value which is a void pointer is redundant. The "
1208 "conversion from void pointer to any other pointer type is guaranteed by the "
1209 "C programming language."
1210 msgstr ""
1211 "强制转换一个void指针返回值是多余的。C语言本身保证了从void指针到其他任何指针"
1212 "类型的转换是没有问题的。"
1214 msgid "\t\tChapter 15: The inline disease\n"
1215 msgstr "\t\t第十五章:内联弊病\n"
1217 msgid ""
1218 "There appears to be a common misperception that gcc has a magic \"make me "
1219 "faster\" speedup option called \"inline\". While the use of inlines can be "
1220 "appropriate (for example as a means of replacing macros, see Chapter 12), "
1221 "it very often is not. Abundant use of the inline keyword leads to a much "
1222 "bigger kernel, which in turn slows the system as a whole down, due to a "
1223 "bigger icache footprint for the CPU and simply because there is less memory "
1224 "available for the pagecache. Just think about it; a pagecache miss causes a "
1225 "disk seek, which easily takes 5 miliseconds. There are a LOT of cpu cycles "
1226 "that can go into these 5 miliseconds."
1227 msgstr ""
1228 "有一个常见的误解是内联函数是gcc提供的可以让代码运行更快的一个选项。虽然使用"
1229 "内联函数有时候是恰当的(比如作为一种替代宏的方式,请看第十二章),不过很多情"
1230 "况下不是这样。inline关键字的过度使用会使内核变大,从而使整个系统运行速度变"
1231 "慢。因为大内核会占用更多的指令高速缓存(译注:一级缓存通常是指令缓存和数据缓"
1232 "存分开的)而且会导致pagecache的可用内存减少。想象一下,一次pagecache未命中就"
1233 "会导致一次磁盘寻址,将耗时5毫秒。5毫秒的时间内CPU能执行很多很多指令。"
1235 msgid ""
1236 "A reasonable rule of thumb is to not put inline at functions that have more "
1237 "than 3 lines of code in them. An exception to this rule are the cases where "
1238 "a parameter is known to be a compiletime constant, and as a result of this "
1239 "constantness you *know* the compiler will be able to optimize most of your "
1240 "function away at compile time. For a good example of this later case, see "
1241 "the kmalloc() inline function."
1242 msgstr ""
1243 "一个基本的原则是如果一个函数有3行以上,就不要把它变成内联函数。这个原则的一"
1244 "个例外是,如果你知道某个参数是一个编译时常量,而且因为这个常量你确定编译器在"
1245 "编译时能优化掉你的函数的大部分代码,那仍然可以给它加上inline关键字。kmalloc"
1246 "()内联函数就是一个很好的例子。"
1248 msgid ""
1249 "Often people argue that adding inline to functions that are static and used "
1250 "only once is always a win since there is no space tradeoff. While this is "
1251 "technically correct, gcc is capable of inlining these automatically without "
1252 "help, and the maintenance issue of removing the inline when a second user "
1253 "appears outweighs the potential value of the hint that tells gcc to do "
1254 "something it would have done anyway."
1255 msgstr ""
1256 "人们经常主张给static的而且只用了一次的函数加上inline,不会有任何损失,因为这"
1257 "种情况下没有什么好权衡的。虽然从技术上说,这是正确的,不过gcc可以在没有提示"
1258 "的情况下自动使其内联,而且其他用户可能会要求移除inline,此种维护上的争论会抵"
1259 "消可以告诉gcc来做某些事情的提示带来的潜在价值。不管有没有inline,这种函数都"
1260 "会被内联。"
1262 msgid "\t\tChapter 16: Function return values and names\n"
1263 msgstr "\t\t第十六章:函数返回值及命名\n"
1265 msgid ""
1266 "Functions can return values of many different kinds, and one of the most "
1267 "common is a value indicating whether the function succeeded or failed.  "
1268 "Such a value can be represented as an error-code integer (-Exxx = failure, "
1269 "0 = success) or a \"succeeded\" boolean (0 = failure, non-zero = success)."
1270 msgstr ""
1271 "函数可以返回很多种不同类型的值,最常见的一种是表明函数执行成功或者失败的值。"
1272 "这样的一个值可以表示为一个错误代码整数(-Exxx=失败,0=成功)或者一个“成"
1273 "功”布尔值(0=失败,非0=成功)。"
1275 msgid ""
1276 "Mixing up these two sorts of representations is a fertile source of "
1277 "difficult-to-find bugs.  If the C language included a strong distinction "
1278 "between integers and booleans then the compiler would find these mistakes "
1279 "for us... but it doesn't.  To help prevent such bugs, always follow this "
1280 "convention:"
1281 msgstr ""
1282 "混合使用这两种表达方式是难于发现的bug的来源。如果C语言本身严格区分整形和布尔"
1283 "型变量,那么编译器就能够帮我们发现这些错误……不过C语言不区分。为了避免产生这"
1284 "种bug,请遵循下面的惯例:"
1286 msgid ""
1287 "\tIf the name of a function is an action or an imperative command,\n"
1288 "\tthe function should return an error-code integer.  If the name\n"
1289 "\tis a predicate, the function should return a \"succeeded\" boolean.\n"
1290 msgstr "\t如果函数的名字是一个动作或者强制性的命令,那么这个函数应该返回错误代码整数。如果是一个判断,那么函数应该返回一个“成功”布尔值。\n"
1292 msgid ""
1293 "For example, \"add work\" is a command, and the add_work() function returns "
1294 "0 for success or -EBUSY for failure.  In the same way, \"PCI device present"
1295 "\" is a predicate, and the pci_dev_present() function returns 1 if it "
1296 "succeeds in finding a matching device or 0 if it doesn't."
1297 msgstr ""
1298 "比如,“add work”是一个命令,所以add_work()函数在成功时返回0,在失败时返回-"
1299 "EBUSY。类似的,因为“PCI device present”是一个判断,所以pci_dev_present()函数"
1300 "在成功找到一个匹配的设备时应该返回1,如果找不到时应该返回0。"
1302 msgid ""
1303 "All EXPORTed functions must respect this convention, and so should all "
1304 "public functions.  Private (static) functions need not, but it is "
1305 "recommended that they do."
1306 msgstr ""
1307 "所有导出(译注:EXPORT)的函数都必须遵守这个惯例,所有的公共函数也都应该如"
1308 "此。私有(static)函数不需要如此,但是我们也推荐这样做。"
1310 msgid ""
1311 "Functions whose return value is the actual result of a computation, rather "
1312 "than an indication of whether the computation succeeded, are not subject to "
1313 "this rule.  Generally they indicate failure by returning some out-of-range "
1314 "result.  Typical examples would be functions that return pointers; they use "
1315 "NULL or the ERR_PTR mechanism to report failure."
1316 msgstr ""
1317 "返回值是实际计算结果而不是计算是否成功的标志的函数不受此惯例的限制。一般的,"
1318 "他们通过返回一些正常值范围之外的结果来表示出错。典型的例子是返回指针的函数,"
1319 "他们使用NULL或者ERR_PTR机制来报告错误。"
1321 msgid "\t\tChapter 17:  Don't re-invent the kernel macros\n"
1322 msgstr "\t\t第十七章:不要重新发明内核宏\n"
1324 msgid ""
1325 "The header file include/linux/kernel.h contains a number of macros that you "
1326 "should use, rather than explicitly coding some variant of them yourself.  "
1327 "For example, if you need to calculate the length of an array, take "
1328 "advantage of the macro"
1329 msgstr ""
1330 "头文件include/linux/kernel.h包含了一些宏,你应该使用它们,而不要自己写一些它"
1331 "们的变种。比如,如果你需要计算一个数组的长度,使用这个宏"
1333 msgid "  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))\n"
1334 msgstr "  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))\n"
1336 msgid ""
1337 "Similarly, if you need to calculate the size of some structure member, use"
1338 msgstr "类似的,如果你要计算某结构体成员的大小,使用"
1340 msgid "  #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))\n"
1341 msgstr "  #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))\n"
1343 msgid ""
1344 "There are also min() and max() macros that do strict type checking if you "
1345 "need them.  Feel free to peruse that header file to see what else is "
1346 "already defined that you shouldn't reproduce in your code."
1347 msgstr ""
1348 "还有可以做严格的类型检查的min()和max()宏,如果你需要可以使用它们。你可以自己"
1349 "看看那个头文件里还定义了什么你可以拿来用的东西,如果有定义的话,你就不应在你"
1350 "的代码里自己重新定义。"
1352 msgid "\t\tAppendix I: References\n"
1353 msgstr "\t\t附录 I:参考\n"
1355 msgid ""
1356 "The C Programming Language, Second Edition by Brian W. Kernighan and Dennis "
1357 "M. Ritchie.  Prentice Hall, Inc., 1988.  ISBN 0-13-110362-8 (paperback), 0-"
1358 "13-110370-9 (hardback).  URL: http://cm.bell-labs.com/cm/cs/cbook/"
1359 msgstr ""
1360 "The C Programming Language, 第二版, 作者Brian W. Kernighan和Dennis M. "
1361 "Ritchie. Prentice Hall, Inc., 1988. ISBN 0-13-110362-8 (软皮), 0-13-110370-"
1362 "9 (硬皮). URL: http://cm.bell-labs.com/cm/cs/cbook/"
1364 msgid ""
1365 "The Practice of Programming by Brian W. Kernighan and Rob Pike.  Addison-"
1366 "Wesley, Inc., 1999.  ISBN 0-201-61586-X.  URL: http://cm.bell-labs.com/cm/"
1367 "cs/tpop/"
1368 msgstr ""
1369 "The Practice of Programming 作者Brian W. Kernighan和Rob Pike.  Addison-"
1370 "Wesley, Inc., 1999.  ISBN 0-201-61586-X.  URL: http://cm.bell-labs.com/cm/"
1371 "cs/tpop/"
1373 msgid ""
1374 "GNU manuals - where in compliance with K&R and this text - for cpp, gcc, "
1375 "gcc internals and indent, all available from http://www.gnu.org/manual/"
1376 msgstr ""
1377 "cpp,gcc,gcc internals和indent的GNU手册——和K&R及本文相符合的部分,全部可以"
1378 "在http://www.gnu.org/manual/找到"
1380 msgid ""
1381 "WG14 is the international standardization working group for the programming "
1382 "language C, URL: http://www.open-std.org/JTC1/SC22/WG14/"
1383 msgstr ""
1384 "WG14是C语言的国际标准化工作组,URL: http://www.open-std.org/JTC1/SC22/WG14/"
1386 msgid ""
1387 "Kernel CodingStyle, by greg@kroah.com at OLS 2002: http://www.kroah.com/"
1388 "linux/talks/ols_2002_kernel_codingstyle_talk/html/"
1389 msgstr ""
1390 "Kernel CodingStyle,作者greg@kroah.com发表于OLS 2002: http://www.kroah.com/"
1391 "linux/talks/ols_2002_kernel_codingstyle_talk/html/"
1393 msgid "--\n"
1394 msgstr "--\n"
1396 msgid "Last updated on 2006-December-06."
1397 msgstr "最后更新于2006年12月6日。"