C++ Logo


Advanced search

[std-proposals] Make C++ support C's standard pragmas

From: blacktea hamburger <greenteahamburger_at_[hidden]>
Date: Sun, 25 Sep 2022 20:31:43 +0800
According to 6.10.6 of C N2176 <https://wg14.link/N2176>:

If the preprocessing token STDC does immediately follow pragma in the
directive (prior to any macro replacement), then no macro replacement is
performed on the directive, and the directive shall have one of the
following forms178) whose meanings are described elsewhere:

   - #pragma STDC FP_CONTRACT on-off-switch
   - #pragma STDC FENV_ACCESS on-off-switch
   - #pragma STDC CX_LIMITED_RANGE on-off-switch

FP_CONTRACT (7.12.2):

The FP_CONTRACT pragma can be used to allow (if the state is “on”) or
disallow (if the state is “off”) the implementation to contract expressions

FENV_ACCESS (7.6.1):

The FENV_ACCESS pragma provides a means to inform the implementation when a
program might access the floating-point environment to test floating-point
status flags or run under non-default floating-point control modes.


The usual mathematical formulas for complex multiply, divide, and absolute
value are problematic because of their treatment of infinities and because
of undue overflow and underflow. The CX_LIMITED_RANGE pragma can be used to
inform the implementation that (where the state is “on”) the usual
mathematical formulas are acceptable.

FP_CONTRACT and FENV_ACCESS can be added to C++ without much effort.
CX_LIMITED_RANGE needs to be changed to apply to std::complex.

Are there other issues?

Received on 2022-09-25 12:32:12