[Cfp-interest 1260] Re: fegetexceptflag()
Jim Thomas
jaswthomas at sbcglobal.net
Fri Feb 15 16:39:02 PST 2019
The only allowed use for the result of fegetexceptflag is as input to fesetexceptflag or fetestexceptflag which say:
"The value of *flagp shall have been set by a previous call to fegetexceptflag whose second
argument represented at least those floating-point exceptions represented by the argument excepts."
So if the second argument to fegetexceptflag is 0, the value of the excepts argument to a function using the result must be 0 too. fesetexceptflag returns zero if its excepts argument is zero. Therefore, fegetexceptflag(I &flagp, 0) can return zero too.
C says:
"7.1.4 Use of library functions
1 Each of the following statements applies unless explicitly stated otherwise in the detailed descriptions
that follow:
— If an argument to a function has an invalid value (such as a value outside the domain of the
function, or a pointer outside the address space of the program, or a null pointer, or a pointer
to non-modifiable storage when the corresponding parameter is not const-qualified) or a type
(after default argument promotion) not expected by a function with a variable number of
arguments, the behavior is undefined."
I don’t think we want/need to say anything about NULL pointers.
> On Feb 12, 2019, at 9:20 AM, Fred J. Tydeman <tydeman at tybor.com> wrote:
>
> Does
> #include <fenv.h>
> fexcept_t flagp;
> fegetexceptflag( &flagp, 0 );
> store anything? Since the 2nd argument is 0, nothing is being asked for.
> Does the function still return 0 (to indicate success)?
>
> If nothing was stored, is
> fegetexceptflag( NULL, 0 );
> valid?
>
>
>> From C2X:
>
> Synopsis
> #include <fenv.h>
> int fegetexceptflag(fexcept_t *flagp,
> int excepts);
>
> Description
> The fegetexceptflag function attempts to store an implementation-defined representation of the
> states of the floating-point status flags indicated by the argument excepts in the object pointed to
> by the argument flagp.
>
> Returns
> The fegetexceptflag function returns zero if the representation was successfully stored. Otherwise,
> it returns a nonzero value.
I suppose we could change this to:
"The fegetexceptflag function returns zero if the excepts argument is zero or the representation was successfully stored. Otherwise,
it returns a nonzero value.”
Though one could argue that if excepts is zero then the store was trivially successful.
- Jim Thomas
>
>
> ---
> Fred J. Tydeman Tydeman Consulting
> tydeman at tybor.com Testing, numerics, programming
> +1 (702) 608-6093 Vice-chair of PL22.11 (ANSI "C")
> Sample C99+FPCE tests: http://www.tybor.com
> Savers sleep well, investors eat well, spenders work forever.
>
> _______________________________________________
> Cfp-interest mailing list
> Cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest
More information about the Cfp-interest
mailing list