预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共20页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

Linuxkernelcodingstyle Thisisashortdocumentdescribingthepreferredcodingstylefor the linuxkernel.Codingstyleisverypersonal,andIwon't_force_my viewsonanybody,butthisiswhatgoesforanythingthatIhaveto be abletomaintain,andI'dpreferitformostotherthingstoo. Please atleastconsiderthepointsmadehere. Firstoff,I'dsuggestprintingoutacopyoftheGNUcoding standards, andNOTreadit.Burnthem,it'sagreatsymbolicgesture. Anyway,heregoes: Chapter1:Indentation Tabsare8characters,andthusindentationsarealso8characters. Therearehereticmovementsthattrytomakeindentations4(oreven 2!) charactersdeep,andthatisakintotryingtodefinethevalueofPI to be3. Rationale:Thewholeideabehindindentationistoclearlydefine where ablockofcontrolstartsandends.Especiallywhenyou'vebeen looking atyourscreenfor20straighthours,you'llfinditaloteasierto see howtheindentationworksifyouhavelargeindentations. Now,somepeoplewillclaimthathaving8-characterindentations makes thecodemovetoofartotheright,andmakesithardtoreadona 80-characterterminalscreen.Theanswertothatisthatifyouneed morethan3levelsofindentation,you'rescrewedanyway,andshould fix yourprogram. Inshort,8-charindentsmakethingseasiertoread,andhavethe added benefitofwarningyouwhenyou'renestingyourfunctionstoodeep. Heedthatwarning. Thepreferredwaytoeasemultipleindentationlevelsinaswitch statementis toalignthe"switch"anditssubordinate"case"labelsinthesame column insteadof"double-indenting"the"case"labels.E.g.: switch(suffix){ case'G': case'g': mem<<=30; break; case'M': case'm': mem<<=20; break; case'K': case'k': mem<<=10; /*fallthrough*/ default: break; } Don'tputmultiplestatementsonasinglelineunlessyouhave somethingtohide: if(condition)do_this; do_something_everytime; Don'tputmultipleassignmentsonasinglelineeither.Kernel codingstyle issupersimple.Avoidtrickyexpressions. Outsideofcomments,documentationandexceptinKconfig,spacesare never usedforindentation,andtheaboveexampleisdeliberatelybroken. Getadecenteditoranddon'tleavewhitespaceattheendoflines. Chapter2