Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.STDLIB.FENV.MACRO.2012

Floating-point exception feature from fenv.h is used.

MISRA C 2012 Rule 21.12: The exception handing features of <fenv.h> should not be used

C99 [Unspecified 27, 28; Undefined 109–111; Implementation J.3.6(8)]

Category: Advisory

Analysis: Decidable, Single Translation Unit

Applies to: C99

Amplification

The identifiers feclearexcept, fegetexceptflag, feraiseexcept, fesetexceptflag and fetestexcept shall not be used and no macro with one of these names shall be expanded.

The macros FE_INEXACT, FE_DIVBYZERO, FE_UNDERFLOW, FE_OVERFLOW, FE_INVALID and FE_ALL_EXCEPT, along with any implementation-defined floating-point exception macros, shall not be used.

Rationale

In some circumstances, the values of the floating-point status flags are unspecified and attempts to access them may lead to undefined behaviour.

The order in which exceptions are raised by the feraiseexcept function is unspecified and could therefore result in a program that has been designed for a certain order not operating correctly.

Example

#include <fenv.h>

void f ( float32_t x, float32_t y ) 
{  
  float32_t 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 */ 
    { 
    } 
  } 
}