Why is the MISRA-C:2012 directive D4.10 raised on #pragma once?
조회 수: 20 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2019년 2월 22일
답변: MathWorks Support Team
2019년 2월 22일
The MISRA-C:2012 directive 4.10 says that "Precautions shall be taken in order to prevent the contents of a header file being included more than once."
In C it is possible to prevent header file to be included more than once thanks to the pragma #pragma once.
But Polyspace will raise a violation of D4.10 on this pragma. Why?
채택된 답변
MathWorks Support Team
2019년 2월 22일
The #pragma once directive, even if supported by most of the compilers, is not part of the C standard.
It is then “implementation-defined”, and in some corner cases, where copied include files or include files with same name are in different include directories, it can lead to unintended behavior.
The MISRA-C:2012 standard does not list this pragma in the description of the directive D4.10.
The two forms given in the standard are:
#if !defined ( identifier )
#define identifier
...
#endif
and
#ifndef identifier
#define identifier
...
#endif
Polyspace follows the MISRA-C:2012 standard and does not consider #pragma once as a valid include guard.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Command-Line Only Options에 대해 자세히 알아보기
제품
릴리스
아직 릴리스를 입력하지 않았습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!