主要内容

MISRA C:2012 Rule 21.12

The standard header file <fenv.h> shall not be used

描述

The standard header file <fenv.h> shall not be used 1 .

理由

在某些情况下,未指定浮点状态标志的值。尝试访问这些值可能会导致未定义行为。

故障排除

如果您预期会出现违规,但未看到该违规,请参阅诊断为何编码规范违规未按预期显示

示例

全部展开

#include <fenv.h>     /* Non-compliant */

void func(float x, float y) {
    float z;

    feclearexcept(FE_DIVBYZERO);              /* Non-compliant */ 
    z = x/y;

    if(fetestexcept (FE_DIVBYZERO))  {        /* Non-compliant */ 
    }
    else {
#pragma STDC FENV_ACCESS ON
        z=x*y;
        if(z>x) {
#pragma STDC FENV_ACCESS OFF
            if(fetestexcept (FE_OVERFLOW)) {  /* Non-compliant */ 
            }
        }
    }
}

在此示例中,当使用标识符 feclearexceptfetestexcept,以及宏 FE_DIVBYZEROFE_OVERFLOW 时,违反了此规则。

检查信息

组:标准库
类别:必需
AGC 类别:必需
PQL 名称:std.misra_c_2012.R21_12

版本历史记录

在 R2015b 中推出

全部展开


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.