F.7.4 Constant expressions

1

An arithmetic constant expression of floating type, other than one in an initializer for an object that has static storage duration, is evaluated (as if) during execution; thus, it is affected by any operative floating-point control modes and raises floating-point exceptions as required by IEC 60559 (provided the state for the FENV_ACCESS pragma is “on”).[1]

2

EXAMPLE

#include <fenv.h>
#pragma STDC FENV_ACCESS ON
void f(void)
{
      float w[] = { 0.0/0.0 };                  //   raises an exception
      static float x = 0.0/0.0;                 //   does not raise an exception
      float y = 0.0/0.0;                        //   raises an exception
      double z = 0.0/0.0;                       //   raises an exception
      /* ... */
}

3

For the static initialization, the division is done at translation time, raising no (execution-time) floating- point exceptions. On the other hand, for the three automatic initializations the invalid division occurs at execution time.

const static double one_third = 1.0/3.0;

Footnotes