cnjenkins 发表于 2007-9-18 11:03

MISRA C 2004

<br /><B>MISRA&nbsp;C&nbsp;2004</B><br /><B>一、开发环境</B><B>(Environment)</B><br /><B>二、语言外延</B><B>(Language&nbsp;Extensions)</B><br /><B>三、注释</B><B>(Documentation)</B><br /><B>四、字符集</B><B>(Character&nbsp;Sets)</B><br /><B>五、标识符</B><B>(Identifiers)</B><br /><B>六、类型</B><B>(Types)</B><br /><B>七、常量</B><B>(Constants)</B><br /><B>八、声明和定义</B><B>(Declarations&nbsp;and&nbsp;Definitions)</B><br /><B>九、初始化</B><B>(Initialisation)</B><br /><B>十、算术类型转换</B><B>(Arithmetic&nbsp;Type&nbsp;Conversion)</B><br /><B>十一、指针类型转换</B><B>(Point&nbsp;Type&nbsp;Conversion)</B><br /><B>十二、表达式</B><B>(Expressions)</B><br /><B>十三、控制表达式</B><B>(Control&nbsp;Statement&nbsp;Expressions)</B><br /><B>十四、控制流</B><B>(Control&nbsp;Flow)</B><br /><B>十五、</B><B>Switch</B><B>语句</B><B>(Switch&nbsp;Statements)</B><br /><B>十六、函数</B><B>(Functions)</B><br /><B>十七、指针和数组</B><B>(Pointers&nbsp;and&nbsp;Arrays)</B><br /><B>十八、结构体和联合体</B><B>(Structures&nbsp;and&nbsp;Unions)</B><br /><B>十九、预处理命令</B><B>(Preprocessing&nbsp;Directives)</B><br /><B>二十、标准库</B><B>(Standard&nbsp;Libraries)</B><br /><B>二十一、运行失败</B><B>(Run-Time&nbsp;Failures)</B>

cnjenkins 发表于 2007-9-18 11:04

一、开发环境(Environment)

<br /><B>一、开发环境</B><B>(Environment)</B><br />1.1&nbsp;All&nbsp;code&nbsp;shall&nbsp;conform&nbsp;to&nbsp;ISO&nbsp;9899:1990“Programming&nbsp;languages&nbsp;–&nbsp;C”,&nbsp;amended&nbsp;and&nbsp;corrected&nbsp;by&nbsp;ISO/IEC&nbsp;9899/COR1:1995,&nbsp;ISO/IEC&nbsp;9899/AMD1:1995,&nbsp;and&nbsp;ISO/IEC&nbsp;9899/COR2:1996.<br />翻译:<br />1.2&nbsp;No&nbsp;reliance&nbsp;shall&nbsp;be&nbsp;placed&nbsp;on&nbsp;undefined&nbsp;or&nbsp;unspecified&nbsp;behaviour.<br />翻译:<br />1.3&nbsp;Multiple&nbsp;compilers&nbsp;and/or&nbsp;languages&nbsp;shall&nbsp;only&nbsp;be&nbsp;used&nbsp;if&nbsp;there&nbsp;is&nbsp;a&nbsp;common&nbsp;defined&nbsp;interface&nbsp;standard&nbsp;for&nbsp;object&nbsp;code&nbsp;to&nbsp;which&nbsp;the&nbsp;languages/compilers/assemblers&nbsp;conform.<br />翻译:<br />1.4&nbsp;The&nbsp;compiler/linker&nbsp;shall&nbsp;be&nbsp;checked&nbsp;to&nbsp;ensure&nbsp;that&nbsp;31&nbsp;character&nbsp;significance&nbsp;and&nbsp;case&nbsp;sensitivity&nbsp;are&nbsp;supported&nbsp;for&nbsp;external&nbsp;identifiers.<br />翻译:<br />1.5&nbsp;Floating-point&nbsp;implementations&nbsp;should&nbsp;comply&nbsp;with&nbsp;a&nbsp;defined&nbsp;floating-point&nbsp;standard.<br />翻译:

cnjenkins 发表于 2007-9-18 11:05

二、语言外延(Language Extensions)

<br />2.1&nbsp;Assembly&nbsp;language&nbsp;shall&nbsp;be&nbsp;encapsulated&nbsp;and&nbsp;isolated.<br />翻译:<br />2.2&nbsp;Source&nbsp;code&nbsp;shall&nbsp;only&nbsp;use&nbsp;/*&nbsp;…&nbsp;*/&nbsp;style&nbsp;comments.<br />翻译:<br />2.3&nbsp;The&nbsp;character&nbsp;sequence&nbsp;/*&nbsp;shall&nbsp;not&nbsp;be&nbsp;used&nbsp;within&nbsp;a&nbsp;comment.<br />翻译:<br />2.4&nbsp;Sections&nbsp;of&nbsp;code&nbsp;should&nbsp;not&nbsp;be&nbsp;“commented&nbsp;out”.<br />翻译:<br />&nbsp;

cnjenkins 发表于 2007-9-18 11:05

三、注释(Documentation)

三、注释(Documentation)<br />3.1&nbsp;All&nbsp;usage&nbsp;of&nbsp;implementation-defined&nbsp;behaviour&nbsp;shall&nbsp;be&nbsp;documented.<br />翻译:<br />3.2&nbsp;The&nbsp;character&nbsp;set&nbsp;and&nbsp;the&nbsp;corresponding&nbsp;encoding&nbsp;shall&nbsp;be&nbsp;documented.<br />翻译:<br />3.3&nbsp;The&nbsp;implementation&nbsp;of&nbsp;integer&nbsp;division&nbsp;in&nbsp;the&nbsp;chosen&nbsp;compiler&nbsp;should&nbsp;be&nbsp;determined,&nbsp;documented&nbsp;and&nbsp;taken&nbsp;into&nbsp;account.<br />翻译:<br />3.4&nbsp;All&nbsp;uses&nbsp;of&nbsp;the&nbsp;#pragma&nbsp;directive&nbsp;shall&nbsp;be&nbsp;documented&nbsp;and&nbsp;explained.<br />翻译:<br />3.5&nbsp;If&nbsp;it&nbsp;is&nbsp;being&nbsp;relied&nbsp;upon,&nbsp;the&nbsp;implementation&nbsp;defined&nbsp;behaviour&nbsp;and&nbsp;packing&nbsp;of&nbsp;bitfields&nbsp;shall&nbsp;be&nbsp;documented.<br />翻译:<br />3.6&nbsp;All&nbsp;libraries&nbsp;used&nbsp;in&nbsp;production&nbsp;code&nbsp;shall&nbsp;be&nbsp;written&nbsp;to&nbsp;comply&nbsp;with&nbsp;the&nbsp;provisions&nbsp;of&nbsp;this&nbsp;document,&nbsp;and&nbsp;shall&nbsp;have&nbsp;been&nbsp;subject&nbsp;to&nbsp;appropriate&nbsp;validation.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:06

四、字符集(Character Sets)

4.1&nbsp;Only&nbsp;those&nbsp;escape&nbsp;sequences&nbsp;that&nbsp;are&nbsp;defined&nbsp;in&nbsp;the&nbsp;ISO&nbsp;C&nbsp;standard&nbsp;shall&nbsp;be&nbsp;used.<br />翻译:<br />4.2&nbsp;Trigraphs&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:07

五、标识符(Identifiers)

5.1&nbsp;Identifiers&nbsp;(internal&nbsp;and&nbsp;external)&nbsp;shall&nbsp;not&nbsp;rely&nbsp;on&nbsp;the&nbsp;significance&nbsp;of&nbsp;more&nbsp;than&nbsp;31&nbsp;characters.<br />翻译:<br />5.2&nbsp;Identifiers&nbsp;in&nbsp;an&nbsp;inner&nbsp;scope&nbsp;shall&nbsp;not&nbsp;use&nbsp;the&nbsp;same&nbsp;name&nbsp;as&nbsp;an&nbsp;identifier&nbsp;in&nbsp;an&nbsp;outer&nbsp;scope,&nbsp;and&nbsp;therefore&nbsp;hide&nbsp;that&nbsp;identifier.<br />翻译:<br />5.3&nbsp;A&nbsp;typedef&nbsp;name&nbsp;shall&nbsp;be&nbsp;a&nbsp;unique&nbsp;identifier.<br />翻译:<br />5.4&nbsp;A&nbsp;tag&nbsp;name&nbsp;shall&nbsp;be&nbsp;a&nbsp;unique&nbsp;identifier.<br />翻译:<br />5.5&nbsp;No&nbsp;object&nbsp;or&nbsp;function&nbsp;identifier&nbsp;with&nbsp;static&nbsp;storage&nbsp;duration&nbsp;should&nbsp;be&nbsp;reused.<br />翻译:<br />5.6&nbsp;No&nbsp;identifier&nbsp;in&nbsp;one&nbsp;name&nbsp;space&nbsp;should&nbsp;have&nbsp;the&nbsp;same&nbsp;spelling&nbsp;as&nbsp;an&nbsp;identifier&nbsp;in&nbsp;another&nbsp;name&nbsp;space,&nbsp;with&nbsp;the&nbsp;exception&nbsp;of&nbsp;structure&nbsp;and&nbsp;union&nbsp;member&nbsp;names.<br />翻译:<br />5.7&nbsp;No&nbsp;identifier&nbsp;name&nbsp;should&nbsp;be&nbsp;reused.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:07

六、类型(Types)

6.1&nbsp;The&nbsp;plain&nbsp;char&nbsp;type&nbsp;shall&nbsp;be&nbsp;used&nbsp;only&nbsp;for&nbsp;the&nbsp;storage&nbsp;and&nbsp;use&nbsp;of&nbsp;character&nbsp;values.<br />翻译:<br />6.2&nbsp;Signed&nbsp;and&nbsp;unsigned&nbsp;char&nbsp;type&nbsp;shall&nbsp;be&nbsp;used&nbsp;only&nbsp;for&nbsp;the&nbsp;storage&nbsp;and&nbsp;use&nbsp;of&nbsp;numeric&nbsp;values.<br />翻译:<br />6.3&nbsp;Typedefs&nbsp;that&nbsp;indicate&nbsp;size&nbsp;and&nbsp;signedness&nbsp;should&nbsp;be&nbsp;used&nbsp;in&nbsp;place&nbsp;of&nbsp;the&nbsp;basic&nbsp;types.<br />翻译:<br />6.4&nbsp;Bit&nbsp;fields&nbsp;shall&nbsp;only&nbsp;be&nbsp;defined&nbsp;to&nbsp;be&nbsp;of&nbsp;type&nbsp;unsigned&nbsp;int&nbsp;or&nbsp;signed&nbsp;int.<br />翻译:<br />6.5&nbsp;Bit&nbsp;fields&nbsp;of&nbsp;type&nbsp;signed&nbsp;int&nbsp;shall&nbsp;be&nbsp;at&nbsp;least&nbsp;2&nbsp;bits&nbsp;long.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:08

七、常量(Constants)

7.1&nbsp;Octal&nbsp;constants&nbsp;(other&nbsp;than&nbsp;zero)&nbsp;and&nbsp;octal&nbsp;escape&nbsp;sequences&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.

cnjenkins 发表于 2007-9-18 11:08

八、声明和定义(Declarations and Definitions)

8.1&nbsp;Functions&nbsp;shall&nbsp;have&nbsp;prototype&nbsp;declarations&nbsp;and&nbsp;the&nbsp;prototype&nbsp;shall&nbsp;be&nbsp;visible&nbsp;at&nbsp;both&nbsp;the&nbsp;function&nbsp;definition&nbsp;and&nbsp;call.<br />翻译:<br />8.2&nbsp;Whenever&nbsp;an&nbsp;object&nbsp;or&nbsp;function&nbsp;is&nbsp;declared&nbsp;or&nbsp;defined,&nbsp;its&nbsp;type&nbsp;shall&nbsp;be&nbsp;explicitly&nbsp;stated.<br />翻译:<br />8.3&nbsp;For&nbsp;each&nbsp;function&nbsp;parameter&nbsp;the&nbsp;type&nbsp;given&nbsp;in&nbsp;the&nbsp;declaration&nbsp;and&nbsp;definition&nbsp;shall&nbsp;be&nbsp;identical,&nbsp;and&nbsp;the&nbsp;return&nbsp;types&nbsp;shall&nbsp;also&nbsp;be&nbsp;identical.<br />翻译:<br />8.4&nbsp;If&nbsp;objects&nbsp;or&nbsp;functions&nbsp;are&nbsp;declared&nbsp;more&nbsp;than&nbsp;once&nbsp;their&nbsp;types&nbsp;shall&nbsp;be&nbsp;compatible.<br />翻译:<br />8.5&nbsp;There&nbsp;shall&nbsp;be&nbsp;no&nbsp;definitions&nbsp;of&nbsp;objects&nbsp;or&nbsp;functions&nbsp;in&nbsp;a&nbsp;header&nbsp;file.<br />翻译:<br />8.6&nbsp;Functions&nbsp;shall&nbsp;be&nbsp;declared&nbsp;at&nbsp;file&nbsp;scope.<br />翻译:<br />8.7&nbsp;Objects&nbsp;shall&nbsp;be&nbsp;defined&nbsp;at&nbsp;block&nbsp;scope&nbsp;if&nbsp;they&nbsp;are&nbsp;only&nbsp;accessed&nbsp;from&nbsp;within&nbsp;a&nbsp;single&nbsp;function.<br />翻译:<br />8.8&nbsp;An&nbsp;external&nbsp;object&nbsp;or&nbsp;function&nbsp;shall&nbsp;be&nbsp;declared&nbsp;in&nbsp;one&nbsp;and&nbsp;only&nbsp;one&nbsp;file.<br />翻译:<br />8.9&nbsp;An&nbsp;identifier&nbsp;with&nbsp;external&nbsp;linkage&nbsp;shall&nbsp;have&nbsp;exactly&nbsp;one&nbsp;external&nbsp;definition.<br />翻译:<br />8.10&nbsp;All&nbsp;declarations&nbsp;and&nbsp;definitions&nbsp;of&nbsp;objects&nbsp;or&nbsp;functions&nbsp;at&nbsp;file&nbsp;scope&nbsp;shall&nbsp;have&nbsp;internal&nbsp;linkage&nbsp;unless&nbsp;external&nbsp;linkage&nbsp;is&nbsp;required.<br />翻译:<br />8.11&nbsp;The&nbsp;static&nbsp;storage&nbsp;class&nbsp;specifier&nbsp;shall&nbsp;be&nbsp;used&nbsp;in&nbsp;definitions&nbsp;and&nbsp;declarations&nbsp;of&nbsp;objects&nbsp;and&nbsp;functions&nbsp;that&nbsp;have&nbsp;internal&nbsp;linkage.<br />翻译:<br />8.12&nbsp;When&nbsp;an&nbsp;array&nbsp;is&nbsp;declared&nbsp;with&nbsp;external&nbsp;linkage,&nbsp;its&nbsp;size&nbsp;shall&nbsp;be&nbsp;stated&nbsp;explicitly&nbsp;or&nbsp;defined&nbsp;implicitly&nbsp;by&nbsp;initialisation.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:31

九、初始化(Initialisation)

9.1&nbsp;All&nbsp;automatic&nbsp;variables&nbsp;shall&nbsp;have&nbsp;been&nbsp;assigned&nbsp;a&nbsp;value&nbsp;before&nbsp;being&nbsp;used.<br />翻译:<br />9.2&nbsp;Braces&nbsp;shall&nbsp;be&nbsp;used&nbsp;to&nbsp;indicate&nbsp;and&nbsp;match&nbsp;the&nbsp;structure&nbsp;in&nbsp;the&nbsp;non-zero&nbsp;initialisation&nbsp;of&nbsp;arrays&nbsp;and&nbsp;structures.<br />翻译:<br />9.3&nbsp;In&nbsp;an&nbsp;enumerator&nbsp;list,&nbsp;the&nbsp;“=”&nbsp;construct&nbsp;shall&nbsp;not&nbsp;be&nbsp;used&nbsp;to&nbsp;explicitly&nbsp;initialise&nbsp;members&nbsp;other&nbsp;than&nbsp;the&nbsp;first,&nbsp;unless&nbsp;all&nbsp;items&nbsp;are&nbsp;explicitly&nbsp;Initialised.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:32

十、算术类型转换(Arithmetic Type Conversion)

10.1&nbsp;The&nbsp;value&nbsp;of&nbsp;an&nbsp;expression&nbsp;of&nbsp;integer&nbsp;type&nbsp;shall&nbsp;not&nbsp;be&nbsp;implicitly&nbsp;converted&nbsp;to&nbsp;a&nbsp;different&nbsp;underlying&nbsp;type&nbsp;if:<br />a)&nbsp;it&nbsp;is&nbsp;not&nbsp;a&nbsp;conversion&nbsp;to&nbsp;a&nbsp;wider&nbsp;integer&nbsp;type&nbsp;of&nbsp;the&nbsp;same&nbsp;signedness,&nbsp;or<br />b)&nbsp;the&nbsp;expression&nbsp;is&nbsp;complex,&nbsp;or<br />c)&nbsp;the&nbsp;expression&nbsp;is&nbsp;not&nbsp;constant&nbsp;and&nbsp;is&nbsp;a&nbsp;function&nbsp;argument,&nbsp;or<br />d)&nbsp;the&nbsp;expression&nbsp;is&nbsp;not&nbsp;constant&nbsp;and&nbsp;is&nbsp;a&nbsp;return&nbsp;expression<br />翻译:<br />10.2&nbsp;The&nbsp;value&nbsp;of&nbsp;an&nbsp;expression&nbsp;of&nbsp;floating&nbsp;type&nbsp;shall&nbsp;not&nbsp;be&nbsp;implicitly&nbsp;converted&nbsp;to&nbsp;a&nbsp;different&nbsp;type&nbsp;if:<br />a)&nbsp;it&nbsp;is&nbsp;not&nbsp;a&nbsp;conversion&nbsp;to&nbsp;a&nbsp;wider&nbsp;floating&nbsp;type,&nbsp;or<br />b)&nbsp;the&nbsp;expression&nbsp;is&nbsp;complex,&nbsp;or<br />c)&nbsp;the&nbsp;expression&nbsp;is&nbsp;a&nbsp;function&nbsp;argument,&nbsp;or<br />d)&nbsp;the&nbsp;expression&nbsp;is&nbsp;a&nbsp;return&nbsp;expression<br />翻译:<br />10.3&nbsp;The&nbsp;value&nbsp;of&nbsp;a&nbsp;complex&nbsp;expression&nbsp;of&nbsp;integer&nbsp;type&nbsp;may&nbsp;only&nbsp;be&nbsp;cast&nbsp;to&nbsp;a&nbsp;type&nbsp;that&nbsp;is&nbsp;narrower&nbsp;and&nbsp;of&nbsp;the&nbsp;same&nbsp;signedness&nbsp;as&nbsp;the&nbsp;underlying&nbsp;type&nbsp;of&nbsp;the&nbsp;expression.<br />翻译:<br />10.4&nbsp;The&nbsp;value&nbsp;of&nbsp;a&nbsp;complex&nbsp;expression&nbsp;of&nbsp;floating&nbsp;type&nbsp;may&nbsp;only&nbsp;be&nbsp;cast&nbsp;to&nbsp;a&nbsp;narrower&nbsp;floating&nbsp;type.<br />翻译:<br />10.5&nbsp;If&nbsp;the&nbsp;bitwise&nbsp;operators&nbsp;~&nbsp;and&nbsp;&lt&lt&nbsp;are&nbsp;applied&nbsp;to&nbsp;an&nbsp;operand&nbsp;of&nbsp;underlying&nbsp;type&nbsp;unsigned&nbsp;char&nbsp;or&nbsp;unsigned&nbsp;short,&nbsp;the&nbsp;result&nbsp;shall&nbsp;be&nbsp;immediately&nbsp;cast&nbsp;to&nbsp;the&nbsp;underlying&nbsp;type&nbsp;of&nbsp;the&nbsp;operand.<br />翻译:<br />10.6&nbsp;A&nbsp;“U”&nbsp;suffix&nbsp;shall&nbsp;be&nbsp;applied&nbsp;to&nbsp;all&nbsp;constants&nbsp;of&nbsp;unsigned&nbsp;type.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:32

十一、指针类型转换(Point Type Conversion)

11.1&nbsp;Conversions&nbsp;shall&nbsp;not&nbsp;be&nbsp;performed&nbsp;between&nbsp;a&nbsp;pointer&nbsp;to&nbsp;a&nbsp;function&nbsp;and&nbsp;any&nbsp;type&nbsp;other&nbsp;than&nbsp;an&nbsp;integral&nbsp;type.<br />翻译:<br />11.2&nbsp;Conversions&nbsp;shall&nbsp;not&nbsp;be&nbsp;performed&nbsp;between&nbsp;a&nbsp;pointer&nbsp;to&nbsp;object&nbsp;and&nbsp;any&nbsp;type&nbsp;other&nbsp;than&nbsp;an&nbsp;integral&nbsp;type,&nbsp;another&nbsp;pointer&nbsp;to&nbsp;object&nbsp;type&nbsp;or&nbsp;a&nbsp;pointer&nbsp;to&nbsp;void.<br />翻译:<br />11.3&nbsp;A&nbsp;cast&nbsp;should&nbsp;not&nbsp;be&nbsp;performed&nbsp;between&nbsp;a&nbsp;pointer&nbsp;type&nbsp;and&nbsp;an&nbsp;integral&nbsp;type.<br />翻译:<br />11.4&nbsp;A&nbsp;cast&nbsp;should&nbsp;not&nbsp;be&nbsp;performed&nbsp;between&nbsp;a&nbsp;pointer&nbsp;to&nbsp;object&nbsp;type&nbsp;and&nbsp;a&nbsp;different&nbsp;pointer&nbsp;to&nbsp;object&nbsp;type.<br />翻译:<br />11.5&nbsp;A&nbsp;cast&nbsp;shall&nbsp;not&nbsp;be&nbsp;performed&nbsp;that&nbsp;removes&nbsp;any&nbsp;const&nbsp;or&nbsp;volatile&nbsp;qualification&nbsp;from&nbsp;the&nbsp;type&nbsp;addressed&nbsp;by&nbsp;a&nbsp;pointer.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:33

十二、表达式(Expressions)

12.1&nbsp;Limited&nbsp;dependence&nbsp;should&nbsp;be&nbsp;placed&nbsp;on&nbsp;C’s&nbsp;operator&nbsp;precedence&nbsp;rules&nbsp;in&nbsp;expressions.<br />翻译:<br />12.2&nbsp;The&nbsp;value&nbsp;of&nbsp;an&nbsp;expression&nbsp;shall&nbsp;be&nbsp;the&nbsp;same&nbsp;under&nbsp;any&nbsp;order&nbsp;of&nbsp;evaluation&nbsp;that&nbsp;the&nbsp;standard&nbsp;permits.<br />翻译:<br />12.3&nbsp;The&nbsp;sizeof&nbsp;operator&nbsp;shall&nbsp;not&nbsp;be&nbsp;used&nbsp;on&nbsp;expressions&nbsp;that&nbsp;contain&nbsp;side&nbsp;effects.<br />翻译:<br />12.4&nbsp;The&nbsp;right&nbsp;hand&nbsp;operand&nbsp;of&nbsp;a&nbsp;logical&nbsp;&&&nbsp;or&nbsp;||&nbsp;operator&nbsp;shall&nbsp;not&nbsp;contain&nbsp;side&nbsp;effects.<br />翻译:<br />12.5&nbsp;The&nbsp;operands&nbsp;of&nbsp;a&nbsp;logical&nbsp;&&&nbsp;or&nbsp;||&nbsp;shall&nbsp;be&nbsp;primary-expressions.<br />翻译:<br />12.6&nbsp;The&nbsp;operands&nbsp;of&nbsp;logical&nbsp;operators&nbsp;(&&,&nbsp;||&nbsp;and&nbsp;!)&nbsp;should&nbsp;be&nbsp;effectively&nbsp;Boolean.&nbsp;Expressions&nbsp;that&nbsp;are&nbsp;effectively&nbsp;Boolean&nbsp;should&nbsp;not&nbsp;be&nbsp;used&nbsp;as&nbsp;operands&nbsp;to&nbsp;operators&nbsp;other&nbsp;than&nbsp;(&&,&nbsp;||&nbsp;and&nbsp;!).<br />翻译:<br />12.7&nbsp;Bitwise&nbsp;operators&nbsp;shall&nbsp;not&nbsp;be&nbsp;applied&nbsp;to&nbsp;operands&nbsp;whose&nbsp;underlying&nbsp;type&nbsp;is&nbsp;signed.<br />翻译:<br />12.8&nbsp;The&nbsp;right&nbsp;hand&nbsp;operand&nbsp;of&nbsp;a&nbsp;shift&nbsp;operator&nbsp;shall&nbsp;lie&nbsp;between&nbsp;zero&nbsp;and&nbsp;one&nbsp;less&nbsp;than&nbsp;the&nbsp;width&nbsp;in&nbsp;bits&nbsp;of&nbsp;the&nbsp;underlying&nbsp;type&nbsp;of&nbsp;the&nbsp;left&nbsp;hand&nbsp;operand.<br />翻译:<br />12.9&nbsp;The&nbsp;unary&nbsp;minus&nbsp;operator&nbsp;shall&nbsp;not&nbsp;be&nbsp;applied&nbsp;to&nbsp;an&nbsp;expression&nbsp;whose&nbsp;underlying&nbsp;type&nbsp;is&nbsp;unsigned.<br />翻译:<br />12.10&nbsp;The&nbsp;comma&nbsp;operator&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />12.11&nbsp;Evaluation&nbsp;of&nbsp;constant&nbsp;unsigned&nbsp;integer&nbsp;expressions&nbsp;should&nbsp;not&nbsp;lead&nbsp;to&nbsp;wrap-around.<br />翻译:<br />12.12&nbsp;The&nbsp;underlying&nbsp;bit&nbsp;representations&nbsp;of&nbsp;floating-point&nbsp;values&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />12.13&nbsp;The&nbsp;increment&nbsp;(++)&nbsp;and&nbsp;decrement&nbsp;(--)&nbsp;operators&nbsp;should&nbsp;not&nbsp;be&nbsp;mixed&nbsp;with&nbsp;other&nbsp;operators&nbsp;in&nbsp;an&nbsp;expression.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:33

十三、控制表达式(Control Statement Expressions)

13.1&nbsp;Assignment&nbsp;operators&nbsp;shall&nbsp;not&nbsp;be&nbsp;used&nbsp;in&nbsp;expressions&nbsp;that&nbsp;yield&nbsp;a&nbsp;Boolean&nbsp;value.<br />翻译:<br />13.2&nbsp;Tests&nbsp;of&nbsp;a&nbsp;value&nbsp;against&nbsp;zero&nbsp;should&nbsp;be&nbsp;made&nbsp;explicit,&nbsp;unless&nbsp;the&nbsp;operand&nbsp;is&nbsp;effectively&nbsp;Boolean.<br />翻译:<br />13.3&nbsp;Floating-point&nbsp;expressions&nbsp;shall&nbsp;not&nbsp;be&nbsp;tested&nbsp;for&nbsp;equality&nbsp;or&nbsp;inequality.<br />翻译:<br />13.4&nbsp;The&nbsp;controlling&nbsp;expression&nbsp;of&nbsp;a&nbsp;for&nbsp;statement&nbsp;shall&nbsp;not&nbsp;contain&nbsp;any&nbsp;objects&nbsp;of&nbsp;floating&nbsp;type.<br />翻译:<br />13.5&nbsp;The&nbsp;three&nbsp;expressions&nbsp;of&nbsp;a&nbsp;for&nbsp;statement&nbsp;shall&nbsp;be&nbsp;concerned&nbsp;only&nbsp;with&nbsp;loop&nbsp;control.<br />翻译:<br />13.6&nbsp;Numeric&nbsp;variables&nbsp;being&nbsp;used&nbsp;within&nbsp;a&nbsp;for&nbsp;loop&nbsp;for&nbsp;iteration&nbsp;counting&nbsp;shall&nbsp;not&nbsp;be&nbsp;modified&nbsp;in&nbsp;the&nbsp;body&nbsp;of&nbsp;the&nbsp;loop.<br />翻译:<br />13.7&nbsp;Boolean&nbsp;operations&nbsp;whose&nbsp;results&nbsp;are&nbsp;invariant&nbsp;shall&nbsp;not&nbsp;be&nbsp;permitted.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:34

十四、控制流(Control Flow)

14.1&nbsp;There&nbsp;shall&nbsp;be&nbsp;no&nbsp;unreachable&nbsp;code.<br />翻译:<br />14.2&nbsp;All&nbsp;non-null&nbsp;statements&nbsp;shall&nbsp;either:<br />a)&nbsp;have&nbsp;at&nbsp;least&nbsp;one&nbsp;side-effect&nbsp;however&nbsp;executed,&nbsp;or<br />b)&nbsp;cause&nbsp;control&nbsp;flow&nbsp;to&nbsp;change.<br />翻译:<br />14.3&nbsp;Before&nbsp;preprocessing,&nbsp;a&nbsp;null&nbsp;statement&nbsp;shall&nbsp;only&nbsp;occur&nbsp;on&nbsp;a&nbsp;line&nbsp;by&nbsp;itself;&nbsp;it&nbsp;may&nbsp;be&nbsp;followed&nbsp;by&nbsp;a&nbsp;comment&nbsp;provided&nbsp;that&nbsp;the&nbsp;first&nbsp;character&nbsp;following&nbsp;the&nbsp;null&nbsp;statement&nbsp;is&nbsp;a&nbsp;white&nbsp;space&nbsp;character.<br />翻译;<br />14.4&nbsp;The&nbsp;goto&nbsp;statement&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />14.5&nbsp;The&nbsp;continue&nbsp;statement&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />14.6&nbsp;For&nbsp;any&nbsp;iteration&nbsp;statement&nbsp;there&nbsp;shall&nbsp;be&nbsp;at&nbsp;most&nbsp;one&nbsp;break&nbsp;statement&nbsp;used&nbsp;for&nbsp;loop&nbsp;termination.<br />翻译:<br />14.7&nbsp;A&nbsp;function&nbsp;shall&nbsp;have&nbsp;a&nbsp;single&nbsp;point&nbsp;of&nbsp;exit&nbsp;at&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;function.<br />翻译:<br />14.8&nbsp;The&nbsp;statement&nbsp;forming&nbsp;the&nbsp;body&nbsp;of&nbsp;a&nbsp;switch,&nbsp;while,&nbsp;do&nbsp;...&nbsp;while&nbsp;or&nbsp;for&nbsp;statement&nbsp;shall&nbsp;be&nbsp;a&nbsp;compound&nbsp;statement.<br />翻译:<br />14.9&nbsp;An&nbsp;if&nbsp;(expression)&nbsp;construct&nbsp;shall&nbsp;be&nbsp;followed&nbsp;by&nbsp;a&nbsp;compound&nbsp;statement.&nbsp;The&nbsp;else&nbsp;keyword&nbsp;shall&nbsp;be&nbsp;followed&nbsp;by&nbsp;either&nbsp;a&nbsp;compound&nbsp;statement,&nbsp;or&nbsp;another&nbsp;if&nbsp;statement.<br />翻译:<br />14.10&nbsp;All&nbsp;if&nbsp;…&nbsp;else&nbsp;if&nbsp;constructs&nbsp;shall&nbsp;be&nbsp;terminated&nbsp;with&nbsp;an&nbsp;else&nbsp;clause.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:34

十五、Switch语句(Switch Statements)

15.1&nbsp;A&nbsp;switch&nbsp;label&nbsp;shall&nbsp;only&nbsp;be&nbsp;used&nbsp;when&nbsp;the&nbsp;most&nbsp;closely-enclosing&nbsp;compound&nbsp;statement&nbsp;is&nbsp;the&nbsp;body&nbsp;of&nbsp;a&nbsp;switch&nbsp;statement.<br />翻译:<br />15.2&nbsp;An&nbsp;unconditional&nbsp;break&nbsp;statement&nbsp;shall&nbsp;terminate&nbsp;every&nbsp;non&nbsp;empty&nbsp;switch&nbsp;clause.<br />翻译:<br />15.3&nbsp;The&nbsp;final&nbsp;clause&nbsp;of&nbsp;a&nbsp;switch&nbsp;statement&nbsp;shall&nbsp;be&nbsp;the&nbsp;default&nbsp;clause.<br />翻译:<br />15.4&nbsp;A&nbsp;switch&nbsp;expression&nbsp;shall&nbsp;not&nbsp;represent&nbsp;a&nbsp;value&nbsp;that&nbsp;is&nbsp;effectively&nbsp;Boolean.<br />翻译:<br />15.5&nbsp;Every&nbsp;switch&nbsp;statement&nbsp;shall&nbsp;have&nbsp;at&nbsp;least&nbsp;one&nbsp;case&nbsp;clause.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:35

十六、函数(Functions)

16.1&nbsp;Functions&nbsp;shall&nbsp;not&nbsp;be&nbsp;defined&nbsp;with&nbsp;a&nbsp;variable&nbsp;number&nbsp;of&nbsp;arguments.<br />翻译:<br />16.2&nbsp;Functions&nbsp;shall&nbsp;not&nbsp;call&nbsp;themselves,&nbsp;either&nbsp;directly&nbsp;or&nbsp;indirectly.<br />翻译:<br />16.3&nbsp;Identifiers&nbsp;shall&nbsp;be&nbsp;given&nbsp;for&nbsp;all&nbsp;of&nbsp;the&nbsp;parameters&nbsp;in&nbsp;a&nbsp;function&nbsp;prototype&nbsp;declaration.<br />翻译:<br />16.4&nbsp;The&nbsp;identifiers&nbsp;used&nbsp;in&nbsp;the&nbsp;declaration&nbsp;and&nbsp;definition&nbsp;of&nbsp;a&nbsp;function&nbsp;shall&nbsp;be&nbsp;identical.<br />翻译:<br />16.5&nbsp;Functions&nbsp;with&nbsp;no&nbsp;parameters&nbsp;shall&nbsp;be&nbsp;declared&nbsp;with&nbsp;parameter&nbsp;type&nbsp;void.<br />翻译:<br />16.6&nbsp;The&nbsp;number&nbsp;of&nbsp;arguments&nbsp;passed&nbsp;to&nbsp;a&nbsp;function&nbsp;shall&nbsp;match&nbsp;the&nbsp;number&nbsp;of&nbsp;parameters.<br />翻译:<br />16.7&nbsp;A&nbsp;pointer&nbsp;parameter&nbsp;in&nbsp;a&nbsp;function&nbsp;prototype&nbsp;should&nbsp;be&nbsp;declared&nbsp;as&nbsp;pointer&nbsp;to&nbsp;const&nbsp;if&nbsp;the&nbsp;pointer&nbsp;is&nbsp;not&nbsp;used&nbsp;to&nbsp;modify&nbsp;the&nbsp;addressed&nbsp;object.<br />翻译:<br />16.8&nbsp;All&nbsp;exit&nbsp;paths&nbsp;from&nbsp;a&nbsp;function&nbsp;with&nbsp;non-void&nbsp;return&nbsp;type&nbsp;shall&nbsp;have&nbsp;an&nbsp;explicit&nbsp;return&nbsp;statement&nbsp;with&nbsp;an&nbsp;expression.<br />翻译:<br />16.9&nbsp;A&nbsp;function&nbsp;identifier&nbsp;shall&nbsp;only&nbsp;be&nbsp;used&nbsp;with&nbsp;either&nbsp;a&nbsp;preceding&nbsp;&,&nbsp;or&nbsp;with&nbsp;a&nbsp;parenthesized&nbsp;parameter&nbsp;list,&nbsp;which&nbsp;may&nbsp;be&nbsp;empty.<br />翻译:<br />16.10&nbsp;If&nbsp;a&nbsp;function&nbsp;returns&nbsp;error&nbsp;information,&nbsp;then&nbsp;that&nbsp;error&nbsp;information&nbsp;shall&nbsp;be&nbsp;tested.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:35

十七、指针和数组(Pointers and Arrays)

17.1&nbsp;Pointer&nbsp;arithmetic&nbsp;shall&nbsp;only&nbsp;be&nbsp;applied&nbsp;to&nbsp;pointers&nbsp;that&nbsp;address&nbsp;an&nbsp;array&nbsp;or&nbsp;array&nbsp;element.<br />翻译:<br />17.2&nbsp;Pointer&nbsp;subtraction&nbsp;shall&nbsp;only&nbsp;be&nbsp;applied&nbsp;to&nbsp;pointers&nbsp;that&nbsp;address&nbsp;elements&nbsp;of&nbsp;the&nbsp;same&nbsp;array.<br />翻译:<br />17.3&nbsp;&gt,&nbsp;&gt=,&nbsp;&lt,&nbsp;&lt=&nbsp;shall&nbsp;not&nbsp;be&nbsp;applied&nbsp;to&nbsp;pointer&nbsp;types&nbsp;except&nbsp;where&nbsp;they&nbsp;point&nbsp;to&nbsp;the&nbsp;same&nbsp;array.<br />翻译:<br />17.4&nbsp;Array&nbsp;indexing&nbsp;shall&nbsp;be&nbsp;the&nbsp;only&nbsp;allowed&nbsp;form&nbsp;of&nbsp;pointer&nbsp;arithmetic.<br />翻译:<br />17.5&nbsp;The&nbsp;declaration&nbsp;of&nbsp;objects&nbsp;should&nbsp;contain&nbsp;no&nbsp;more&nbsp;than&nbsp;2&nbsp;levels&nbsp;of&nbsp;pointer&nbsp;indirection.<br />翻译:<br />17.6&nbsp;The&nbsp;address&nbsp;of&nbsp;an&nbsp;object&nbsp;with&nbsp;automatic&nbsp;storage&nbsp;shall&nbsp;not&nbsp;be&nbsp;assigned&nbsp;to&nbsp;another&nbsp;object&nbsp;that&nbsp;may&nbsp;persist&nbsp;after&nbsp;the&nbsp;first&nbsp;object&nbsp;has&nbsp;ceased&nbsp;to&nbsp;exist.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:36

十八、结构体和联合体(Structures and Unions)

18.1&nbsp;All&nbsp;structure&nbsp;and&nbsp;union&nbsp;types&nbsp;shall&nbsp;be&nbsp;complete&nbsp;at&nbsp;the&nbsp;end&nbsp;of&nbsp;a&nbsp;translation&nbsp;unit.<br />翻译:<br />18.2&nbsp;An&nbsp;object&nbsp;shall&nbsp;not&nbsp;be&nbsp;assigned&nbsp;to&nbsp;an&nbsp;overlapping&nbsp;object.<br />翻译:<br />18.3&nbsp;An&nbsp;area&nbsp;of&nbsp;memory&nbsp;shall&nbsp;not&nbsp;be&nbsp;reused&nbsp;for&nbsp;unrelated&nbsp;purposes.<br />翻译:<br />18.4&nbsp;Unions&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />

cnjenkins 发表于 2007-9-18 11:36

十九、预处理命令(Preprocessing Directives)

19.1&nbsp;#include&nbsp;statements&nbsp;in&nbsp;a&nbsp;file&nbsp;should&nbsp;only&nbsp;be&nbsp;preceded&nbsp;by&nbsp;other&nbsp;preprocessor&nbsp;directives&nbsp;or&nbsp;comments.<br />翻译:<br />19.2&nbsp;Non-standard&nbsp;characters&nbsp;should&nbsp;not&nbsp;occur&nbsp;in&nbsp;header&nbsp;file&nbsp;names&nbsp;in&nbsp;#include&nbsp;directives.<br />翻译:<br />19.3&nbsp;The&nbsp;#include&nbsp;directive&nbsp;shall&nbsp;be&nbsp;followed&nbsp;by&nbsp;either&nbsp;a&nbsp;&ltfilename&gt&nbsp;or&nbsp;&quot;filename&quot;&nbsp;sequence.<br />翻译:<br />19.4&nbsp;C&nbsp;macros&nbsp;shall&nbsp;only&nbsp;expand&nbsp;to&nbsp;a&nbsp;braced&nbsp;initialiser,&nbsp;a&nbsp;constant,&nbsp;a&nbsp;parenthesized&nbsp;expression,&nbsp;a&nbsp;type&nbsp;qualifier,&nbsp;a&nbsp;storage&nbsp;class&nbsp;specifier,&nbsp;or&nbsp;a&nbsp;do-while-zero&nbsp;construct.<br />翻译:<br />19.5&nbsp;Macros&nbsp;shall&nbsp;not&nbsp;be&nbsp;#define’d&nbsp;or&nbsp;#undef’d&nbsp;within&nbsp;a&nbsp;block.<br />翻译:<br />19.6&nbsp;#undef&nbsp;shall&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />19.7&nbsp;A&nbsp;function&nbsp;should&nbsp;be&nbsp;used&nbsp;in&nbsp;preference&nbsp;to&nbsp;a&nbsp;function-like&nbsp;macro.<br />翻译:<br />19.8&nbsp;A&nbsp;function-like&nbsp;macro&nbsp;shall&nbsp;not&nbsp;be&nbsp;invoked&nbsp;without&nbsp;all&nbsp;of&nbsp;its&nbsp;arguments.<br />翻译:<br />19.9&nbsp;Arguments&nbsp;to&nbsp;a&nbsp;function-like&nbsp;macro&nbsp;shall&nbsp;not&nbsp;contain&nbsp;tokens&nbsp;that&nbsp;look&nbsp;like&nbsp;preprocessing&nbsp;directives.<br />翻译:<br />19.10&nbsp;In&nbsp;the&nbsp;definition&nbsp;of&nbsp;a&nbsp;function-like&nbsp;macro&nbsp;each&nbsp;instance&nbsp;of&nbsp;a&nbsp;parameter&nbsp;shall&nbsp;be&nbsp;enclosed&nbsp;in&nbsp;parentheses&nbsp;unless&nbsp;it&nbsp;is&nbsp;used&nbsp;as&nbsp;the&nbsp;operand&nbsp;of&nbsp;#&nbsp;or&nbsp;##.<br />翻译:<br />19.11&nbsp;All&nbsp;macro&nbsp;identifiers&nbsp;in&nbsp;preprocessor&nbsp;directives&nbsp;shall&nbsp;be&nbsp;defined&nbsp;before&nbsp;use,&nbsp;except&nbsp;in&nbsp;#ifdef&nbsp;and&nbsp;#ifndef&nbsp;preprocessor&nbsp;directives&nbsp;and&nbsp;the&nbsp;defined()&nbsp;operator.<br />翻译:<br />19.12&nbsp;There&nbsp;shall&nbsp;be&nbsp;at&nbsp;most&nbsp;one&nbsp;occurrence&nbsp;of&nbsp;the&nbsp;#&nbsp;or&nbsp;##&nbsp;operators&nbsp;in&nbsp;a&nbsp;single&nbsp;macro&nbsp;definition.<br />翻译:<br />19.13&nbsp;The&nbsp;#&nbsp;and&nbsp;##&nbsp;operators&nbsp;should&nbsp;not&nbsp;be&nbsp;used.<br />翻译:<br />19.14&nbsp;The&nbsp;defined&nbsp;preprocessor&nbsp;operator&nbsp;shall&nbsp;only&nbsp;be&nbsp;used&nbsp;in&nbsp;one&nbsp;of&nbsp;the&nbsp;two&nbsp;standard&nbsp;forms.<br />翻译;<br />19.15&nbsp;Precautions&nbsp;shall&nbsp;be&nbsp;taken&nbsp;in&nbsp;order&nbsp;to&nbsp;prevent&nbsp;the&nbsp;contents&nbsp;of&nbsp;a&nbsp;header&nbsp;file&nbsp;being&nbsp;included&nbsp;twice.<br />翻译:<br />19.16&nbsp;Preprocessing&nbsp;directives&nbsp;shall&nbsp;be&nbsp;syntactically&nbsp;meaningful&nbsp;even&nbsp;when&nbsp;excluded&nbsp;by&nbsp;the&nbsp;preprocessor.<br />翻译:<br />19.17&nbsp;All&nbsp;#else,&nbsp;#elif&nbsp;and&nbsp;#endif&nbsp;preprocessor&nbsp;directives&nbsp;shall&nbsp;reside&nbsp;in&nbsp;the&nbsp;same&nbsp;file&nbsp;as&nbsp;the&nbsp;#if&nbsp;or&nbsp;#ifdef&nbsp;directive&nbsp;to&nbsp;which&nbsp;they&nbsp;are&nbsp;related.<br />翻译:<br />
页: [1] 2
查看完整版本: MISRA C 2004