跳转到内容

MISRA C:修订间差异

维基百科,自由的百科全书
删除的内容 添加的内容
InternetArchiveBot留言 | 贡献
补救1个来源,并将0个来源标记为失效。) #IABot (v2.0.9.5
 
(未显示7个用户的10个中间版本)
第12行: 第12行:
|dead-url = yes
|dead-url = yes
}}</ref>
}}</ref>
,不過其他產業也逐漸開始使用MISRA C:包括航空、電信、國防、醫療設備、鐵路等領域中都已有廠商使用MISRA C。<ref>{{Cite web |url=http://www.cosmicsoftware.com/misra.php |title=存档副本 |access-date=2012-04-24 |archive-url=https://web.archive.org/web/20120212045417/http://www.cosmicsoftware.com/misra.php |archive-date=2012-02-12 |dead-url=yes }}</ref><ref>http://www.ldra.com/misrac.asp</ref>
,不過其他產業也逐漸開始使用MISRA C:包括航空、電信、國防、醫療設備、鐵路等領域中都已有廠商使用MISRA C。<ref>{{Cite web |url=http://www.cosmicsoftware.com/misra.php |title=存档副本 |access-date=2012-04-24 |archive-url=https://web.archive.org/web/20120212045417/http://www.cosmicsoftware.com/misra.php |archive-date=2012-02-12 |dead-url=yes }}</ref><ref>{{Cite web |url=http://www.ldra.com/misrac.asp |title=存档副本 |accessdate=2012-04-24 |archive-date=2012-03-17 |archive-url=https://web.archive.org/web/20120317190208/http://www.ldra.com/misrac.asp |dead-url=no }}</ref>


MISRA C的第一版《Guidelines for the use of the C language in vehicle based software》在1998年發行,一般稱為MISRA-C:1998.<ref>[http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx A brief history of MISRA C]</ref>。MISRA-C:1998有127項規則,規則從1號編號到127號,其中有93項是強制要求,其餘的34項是推薦使用的規則。
MISRA C的第一版《Guidelines for the use of the C language in vehicle based software》在1998年發行,一般稱為MISRA-C:1998.<ref>{{Cite web |url=http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx |title=A brief history of MISRA C |accessdate=2012-04-24 |archive-date=2017-06-07 |archive-url=https://web.archive.org/web/20170607124934/https://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx |dead-url=no }}</ref>。MISRA-C:1998有127項規則,規則從1號編號到127號,其中有93項是強制要求,其餘的34項是推薦使用的規則。


在2004年時發行了第二版的MISRA C的第一版《Guidelines for the use of the C language in critical systems》(或稱作MISRA-C:2004),其中有許多重要建議事項的變更,其規則也重新編號。MISRA-C:2004有141項規則,其中121項是強制要求,其餘的20項是推薦使用的規則。規則分為21類,從「開發環境」到「運行期錯誤」<ref>[http://eetimes.com/discussion/beginner-s-corner/4023981/Introduction-to-MISRA-C Introduction-to-MISRA-C</ref>。
在2004年時發行了第二版的MISRA C的第一版《Guidelines for the use of the C language in critical systems》(或稱作MISRA-C:2004),其中有許多重要建議事項的變更,其規則也重新編號。MISRA-C:2004有141項規則,其中121項是強制要求,其餘的20項是推薦使用的規則。規則分為21類,從「開發環境」到「運行期錯誤」<ref>[http://eetimes.com/discussion/beginner-s-corner/4023981/Introduction-to-MISRA-C {{Wayback|url=http://eetimes.com/discussion/beginner-s-corner/4023981/Introduction-to-MISRA-C |date=20120813183716 }} Introduction-to-MISRA-C</ref>。


==規則舉例==
==規則舉例==
第23行: 第23行:


[[C动态内存分配|動態分配記憶體]]功能是C語言的一大特色,可以在運行期依實際需求用malloc分配記憶體,在不使用此記憶體時再用free歸還,但許多問題也和未正確處理動態分配記憶體功能有關,例如MISRA-C:2004的規則20.4為「不能使用动态堆的内存分配」,限制malloc、free等程序的使用。
[[C动态内存分配|動態分配記憶體]]功能是C語言的一大特色,可以在運行期依實際需求用malloc分配記憶體,在不使用此記憶體時再用free歸還,但許多問題也和未正確處理動態分配記憶體功能有關,例如MISRA-C:2004的規則20.4為「不能使用动态堆的内存分配」,限制malloc、free等程序的使用。


C語言 程式碼 <U>''if (x = y)''</U> 是完全合法且有效的 C語言 語句,但很可能是由於意外使用賦值運算子(=)而不是相等運算子(==)而導致的鍵入錯誤。
規則 8.18.2 表示 不應使用賦值運算子的結果,以確保報告此類程式碼並審查其正確性。


==工具==
==工具==
有許多工具聲稱可以檢查代碼和MISRA規則相容性,不過MISRA沒有相關認證的程序<ref>[http://www.misra-c.com/MISRACFAQ/tabid/168/Default.aspx faqs]</ref>。相關工具可以幫助使用者評估和比較檢查的結果,也會提供一些可符合MISRA-C規定的指南。
有許多工具聲稱可以檢查代碼和MISRA規則相容性,不過MISRA沒有相關認證的程序<ref>{{Cite web |url=http://www.misra-c.com/MISRACFAQ/tabid/168/Default.aspx |title=faqs |accessdate=2012-04-24 |archive-date=2017-07-06 |archive-url=https://web.archive.org/web/20170706172941/https://www.misra-c.com/MISRACFAQ/tabid/168/Default.aspx |dead-url=no }}</ref>。相關工具可以幫助使用者評估和比較檢查的結果,也會提供一些可符合MISRA-C規定的指南。


大部份的規定可以用支援[[靜態代碼分析]]的工具檢查,有些規定需要用支援{{le|動態代碼分析|Dynamic program analysis}}的工具檢查。
大部份的規定可以用支援[[靜態代碼分析]]的工具檢查,有些規定需要用支援{{le|動態代碼分析|Dynamic program analysis}}的工具檢查。


;以下是一些可以配合MISRA C規則進行檢查的工具:
;以下是一些可以配合MISRA C規則進行檢查的工具:
*[https://checkmarx.com/ Checkmarx] {{Wayback|url=https://checkmarx.com/ |date=20240530091152 }}
* [[Polyspace]]<ref>[http://www.sourcewire.com/releases/rel_display.php?relid=19765 PolySpace announces MISRA compliance checker]</ref>
* [[Polyspace]]<ref>{{Cite web |url=http://www.sourcewire.com/releases/rel_display.php?relid=19765 |title=PolySpace announces MISRA compliance checker |accessdate=2012-04-24 |archive-date=2019-10-18 |archive-url=https://web.archive.org/web/20191018083352/https://pressreleases.responsesource.com/news/19765/polyspace-announces-misra-compliance-checker/ |dead-url=no }}</ref>
* {{link-en|Coverity|Coverity}}<ref>[http://www.coverity.com/coverity5/5-steps.html The 5 Steps]</ref>
* {{link-en|GrammaTech|GrammaTech}}
* {{link-en|GrammaTech|GrammaTech}}
* {{link-en|Klocwork|Klocwork}}<ref>[http://www.klocwork.com/solutions/misra-coding-standards/index.php MISRA Coding Standards]</ref>
* {{link-en|Klocwork|Klocwork}}<ref>{{Cite web |url=http://www.klocwork.com/solutions/misra-coding-standards/index.php |title=MISRA Coding Standards |access-date=2012-04-24 |archive-date=2014-10-04 |archive-url=https://web.archive.org/web/20141004234804/http://www.klocwork.com/solutions/misra-coding-standards/index.php }}</ref>
* {{link-en|LDRA|Liverpool Data Research Associates}}<ref>[http://www.ldra.com/zh/solutions/by-standard-adherence/misra-c2004 LDRA工具套件的MISRA-C: 2004验证] {{webarchive|url=https://archive.is/20120904094435/http://www.ldra.com/zh/solutions/by-standard-adherence/misra-c2004 |date=2012-09-04 }}</ref>
* {{link-en|Coverity|Coverity}}<ref>{{Cite web |url=http://www.coverity.com/coverity5/5-steps.html |title=The 5 Steps |accessdate=2012-04-24 |archive-date=2012-08-20 |archive-url=https://web.archive.org/web/20120820115122/http://www.coverity.com/coverity5/5-steps.html |dead-url=no }}</ref>
* {{link-en|LDRA|Liverpool Data Research Associates}}<ref>{{Cite web |url=http://www.ldra.com/zh/solutions/by-standard-adherence/misra-c2004 |title=LDRA工具套件的MISRA-C: 2004验证 |accessdate=2012-04-24 |archive-date=2012-09-04 |archive-url=https://archive.today/20120904094435/http://www.ldra.com/zh/solutions/by-standard-adherence/misra-c2004 |dead-url=no }}</ref>
* {{link-en|Parasoft|Parasoft}}<ref>[http://www.parasoft.com/jsp/standards/compliance_misra.jsp MISRA Compliance]</ref>
* {{link-en|Parasoft|Parasoft}}<ref>{{Cite web |url=http://www.parasoft.com/jsp/standards/compliance_misra.jsp |title=MISRA Compliance |accessdate=2012-04-24 |archive-date=2013-10-22 |archive-url=https://web.archive.org/web/20131022235253/http://www.parasoft.com/jsp/standards/compliance_misra.jsp |dead-url=no }}</ref>
* {{link-en|PC-Lint|PC-Lint}}<ref>[http://www.keil.com/pclint/ PC-Lint]</ref>
* {{link-en|PC-Lint|PC-Lint}}<ref>{{Cite web |url=http://www.keil.com/pclint/ |title=PC-Lint |accessdate=2012-04-24 |archive-date=2020-09-29 |archive-url=https://web.archive.org/web/20200929013024/https://www.keil.com/pclint/ |dead-url=no }}</ref>
* {{link-en|QA-C|QA-C}}<ref>[http://www.programmingresearch.com/products/qac/ QA·C]</ref>
* {{link-en|QA-C|QA-C}}<ref>{{Cite web |url=http://www.programmingresearch.com/products/qac/ |title=QA·C |accessdate=2012-04-24 |archive-date=2016-04-15 |archive-url=https://web.archive.org/web/20160415233133/http://www.programmingresearch.com/products/qac/ |dead-url=no }}</ref>
* {{link-en|Understand (軟體)|Understand (software)}}
* {{link-en|Understand (軟體)|Understand (software)}}


;以下是一些可以配合MISRA C規則進行檢查的編譯器:
;以下是一些可以配合MISRA C規則進行檢查的編譯器:
* {{link-en|Green Hills軟體|Green Hills Software}}<ref>[http://www.ghs.com/products/misrac.html MISRA C Support]</ref>
* {{link-en|Green Hills軟體|Green Hills Software}}<ref>{{Cite web |url=http://www.ghs.com/products/misrac.html |title=MISRA C Support |accessdate=2012-04-24 |archive-date=2018-11-11 |archive-url=https://web.archive.org/web/20181111211655/https://www.ghs.com/products/misrac.html |dead-url=no }}</ref>
* {{link-en|IAR系統|IAR Systems}}<ref>{{Cite web |url=http://www.iar.com/en/Products/IAR-Embedded-Workbench/Technology/MISRA-C/ |title=MISRA C |access-date=2012-04-24 |archive-url=https://web.archive.org/web/20120427191051/http://www.iar.com/en/Products/IAR-Embedded-Workbench/Technology/MISRA-C/ |archive-date=2012-04-27 |dead-url=yes }}</ref>
* {{link-en|IAR系統|IAR Systems}}<ref>{{Cite web |url=http://www.iar.com/en/Products/IAR-Embedded-Workbench/Technology/MISRA-C/ |title=MISRA C |access-date=2012-04-24 |archive-url=https://web.archive.org/web/20120427191051/http://www.iar.com/en/Products/IAR-Embedded-Workbench/Technology/MISRA-C/ |archive-date=2012-04-27 |dead-url=yes }}</ref>


==相關條目==
==相關條目==
*[[代码风格]]
*[[代码风格]]
*[[The Power of 10]]


==參考資料==
==參考資料==
{{reflist}}
{{reflist|2}}


==外部連結==
==外部連結==
* [http://www.misra.org.uk MISRA 網站]
* [http://www.misra.org.uk MISRA 網站] {{Wayback|url=http://www.misra.org.uk/ |date=20110727141027 }}
{{Embedded systems}}
{{Embedded systems}}
[[Category:计算机标准]]
[[Category:计算机标准]]

2024年5月31日 (五) 05:31的最新版本

MISRA C是由汽車產業軟體可靠性協會英语Motor Industry Software Reliability Association(MISRA)提出的C語言開發標準。其目的是在增進嵌入式系統的安全性及可移植性。針對C++語言也有對應的標準MISRA C++

MISRA C一開始主要是針對汽車產業[1] ,不過其他產業也逐漸開始使用MISRA C:包括航空、電信、國防、醫療設備、鐵路等領域中都已有廠商使用MISRA C。[2][3]

MISRA C的第一版《Guidelines for the use of the C language in vehicle based software》在1998年發行,一般稱為MISRA-C:1998.[4]。MISRA-C:1998有127項規則,規則從1號編號到127號,其中有93項是強制要求,其餘的34項是推薦使用的規則。

在2004年時發行了第二版的MISRA C的第一版《Guidelines for the use of the C language in critical systems》(或稱作MISRA-C:2004),其中有許多重要建議事項的變更,其規則也重新編號。MISRA-C:2004有141項規則,其中121項是強制要求,其餘的20項是推薦使用的規則。規則分為21類,從「開發環境」到「運行期錯誤」[5]

規則舉例

[编辑]

MISRA C的一些規則是針對運算符的限制,例如MISRA-C:2004的規則12.10為「不要使用逗号运算符」,也可以用其他方式達到一樣的效果。

動態分配記憶體功能是C語言的一大特色,可以在運行期依實際需求用malloc分配記憶體,在不使用此記憶體時再用free歸還,但許多問題也和未正確處理動態分配記憶體功能有關,例如MISRA-C:2004的規則20.4為「不能使用动态堆的内存分配」,限制malloc、free等程序的使用。


C語言 程式碼 if (x = y) 是完全合法且有效的 C語言 語句,但很可能是由於意外使用賦值運算子(=)而不是相等運算子(==)而導致的鍵入錯誤。 規則 8.18.2 表示 不應使用賦值運算子的結果,以確保報告此類程式碼並審查其正確性。

工具

[编辑]

有許多工具聲稱可以檢查代碼和MISRA規則相容性,不過MISRA沒有相關認證的程序[6]。相關工具可以幫助使用者評估和比較檢查的結果,也會提供一些可符合MISRA-C規定的指南。

大部份的規定可以用支援靜態代碼分析的工具檢查,有些規定需要用支援動態代碼分析英语Dynamic program analysis的工具檢查。

以下是一些可以配合MISRA C規則進行檢查的工具:
以下是一些可以配合MISRA C規則進行檢查的編譯器:

相關條目

[编辑]

參考資料

[编辑]
  1. ^ 確保嵌入式系統的網路安全性. 電子工程專輯. 2006-04-28 [2012-04-24]. (原始内容存档于2013-10-04) (中文). 
  2. ^ 存档副本. [2012-04-24]. (原始内容存档于2012-02-12). 
  3. ^ 存档副本. [2012-04-24]. (原始内容存档于2012-03-17). 
  4. ^ A brief history of MISRA C. [2012-04-24]. (原始内容存档于2017-06-07). 
  5. ^ ([//web.archive.org/web/20120813183716/http://eetimes.com/discussion/beginner-s-corner/4023981/Introduction-to-MISRA-C 页面存档备份,存于互联网档案馆) Introduction-to-MISRA-C
  6. ^ faqs. [2012-04-24]. (原始内容存档于2017-07-06). 
  7. ^ PolySpace announces MISRA compliance checker. [2012-04-24]. (原始内容存档于2019-10-18). 
  8. ^ MISRA Coding Standards. [2012-04-24]. (原始内容存档于2014-10-04). 
  9. ^ The 5 Steps. [2012-04-24]. (原始内容存档于2012-08-20). 
  10. ^ LDRA工具套件的MISRA-C: 2004验证. [2012-04-24]. (原始内容存档于2012-09-04). 
  11. ^ MISRA Compliance. [2012-04-24]. (原始内容存档于2013-10-22). 
  12. ^ PC-Lint. [2012-04-24]. (原始内容存档于2020-09-29). 
  13. ^ QA·C. [2012-04-24]. (原始内容存档于2016-04-15). 
  14. ^ MISRA C Support. [2012-04-24]. (原始内容存档于2018-11-11). 
  15. ^ MISRA C. [2012-04-24]. (原始内容存档于2012-04-27). 

外部連結

[编辑]