P99

◆ P99_THROW_CALL_RANGE

#define P99_THROW_CALL_RANGE (   F,
  ... 
)
Value:
P00_THROW_CALL_RANGE_ \
(F, \
(P99_SER(P00_THROW_CALL_RANGE_CASE, P99_STD_REAL_TYPES)), \
__VA_ARGS__)

Wrap a function call to F such that it throws an error on failure.

Many functions in the C and POSIX standards set errno to ERANGE to signal an under- or overflow. This wrapper makes this transparent such that it ensures that errno is always checked, and if an error occurs a value is thrown.

If the error is ERANGE the value of INT_MAX is thrown for an overflow and INT_MIN for a negative overflow. If the return type of F is a floating point type ERANGE could also be set for a value that is too close to 0. In that case ERANGE is thrown directly.

If errno has another non-zero value that value is thrown.

Returns
the value of the function call if the call was successful. Never returns if it wasn't.
See also
P99_THROW_CALL_NEG for a similar macro that checks if the return value is negative
P99_THROW_CALL_VOIDP for a similar macro that checks a pointer return value
Remarks
This is only implemented for the real arithmetic types by means of a type generic macro.
argument 0 maybe evaluated several times for its type but only once for its value
argument 1 maybe evaluated several times for its type but only once for its value
argument 2 maybe evaluated several times for its type but only once for its value
argument 3 maybe evaluated several times for its type but only once for its value
argument 4 maybe evaluated several times for its type but only once for its value

Definition at line 249 of file p99_try.h.

P99_SER
#define P99_SER(MACRO,...)
Apply the macro MACRO to the rest of the argument list.
Definition: p99_for.h:264
P99_STD_REAL_TYPES
#define P99_STD_REAL_TYPES
Definition: p99_type.h:290