N1503=03-0086 PROPOSED ADDITIONS TO TR-1 TO IMPROVE COMPATIBILITY WITH C99 P.J. Plauger Dinkumware, Ltd. pjp@dinkumware.com In an earlier document (WG21/N1372) I described in general terms the functions and type definitions defined in the revised C standard ISO 9899:1999 (a.k.a. C99) that are not present in Standard C++. This document proposes adding to TR-1 enough of those functions and type definitions to dramatically reduce incompatibilities between programs written in C99 and those written in C++ with TR-1. For precise details of each proposed addition, see the C99 Standard. I intentionally omit (for now) any use of the restrict keyword or other language extensions unique to C99 -- with one exception. Any use of the type long long is replaced here with the type _Longlong, and any use of the type unsigned long long is replaced here with the type _ULonglong. These types are defined idempotently in any header that needs them. They can be defined as long and unsigned long, respectively, on an implementation that has no equivalent to long long. HEADERS AND Add the headers and , which simply include the existing C++ header , which add: -- overloads for the three complex types for the functions asin, asinh, atan, atanh, and fabs -- additional overloads for the above so that any integer argument behaves the same as the version with a double argument, with the integer argument converted to double -- additional overloads for the above so that any mixture of double and float complex arguments behaves the same as two double complex arguments -- additional overloads for the above so that any mixture of long double and float complex arguments behaves the same as two long double complex arguments -- additional overloads for the above so that any mixture of double and long double complex arguments behaves the same as two long double complex arguments Moreover, it is recommended that an implementation supporting the C99 complex types in C++ make them compatible with the template specializations complex, complex, and complex. EXISTING HEADERS AND Add the function: isblank which matches at least space and tab (plus other locale-specific blank characters outside the "C" locale). HEADERS AND Add the headers and , which defines various macros, types, and functions for controlling the floating-point environment. Specifically, they define the macros: -- for exception control: FE_ALL_EXCEPT FE_DIVBYZERO FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW -- for rounding-mode control: FE_DOWNWARD FE_TONEAREST FE_TOWARDZERO FE_UPWARD -- for the default floating-point environment: FE_DFL_ENV They define the types: -- for the floating-point environment: fenv_t -- for the exception mask: fexcept_t And they define the functions: feclearexcept fegetenv fegetexceptflag fegetround feholdexcept feraiseexcept fesetenv fesetexceptflag fesetround fetestexcept feupdateenv EXISTING HEADERS AND Add the macros: FLT_EVAL_METHOD DECIMAL_DIG EXISTING HEADER Add the format flag: hexfloat with the value (fixed|scientific). And add a manipulator of the same name, which sets floatfield to hexfloat. HEADERS and Add the headers and , which declare several functions for manipulating values of type intmax_t, a synonym for the largest integer type. They also define a slew of macros that supply the appropriate scan and print conversion specifiers for the integer types defined in . The macros are of the form: {PRI SCN}{d i o u x X}[FAST LEAST]{8 16 32 64} {PRI SCN}{d i o u x X}{MAX PTR} They define the type: imaxdiv_t They define functions that manipulate intmax_t values: imaxabs imaxdiv strtoimax strtoumax wcstoimax wcstoumax And they define overloads on intmax_t for the functions: abs div EXISTING HEADERS AND Add the macros: LLONG_MIN LLONG_MAX ULLONG_MAX EXISTING HEADER Add explicit specializations of template class numeric_limits for _Longlong and _ULonglong (assuming they differ from long and unsigned long). EXISTING HEADER Change num_put for floating types so that if floatfield == hexfloat, the effective printf conversion specifier is %a or %A. EXISTING HEADERS AND Add the macros: -- for reporting the presence of fused multiply/add FP_FAST_FMA FP_FAST_FMAF FP_FAST_FMAL -- for error returns from function ilogb FP_ILOGB0 FP_ILOGBNAN -- for category returns from macro fpclassify FP_INFINITE FP_NAN FP_NORMAL FP_SUBNORMAL FP_ZERO -- for variants of HUGE_VAL HUGE_VALF HUGE_VALL -- for special floating-point values INFINITY NAN -- for controlling the handling of math errors MATH_ERRNO MATH_ERREXCEPT math_errhandling Add the types: -- for tighter control over computational types double_t float_t And add a gazillion functions: -- acosh, asinh, atanh, cbrt, copysign, erf, erfc, exp2, expm1, fdim, fma, fmax, fmin, hypot, ilogb, lgamma, llrint, llround, log1p, log2, logb, lrint, lround, nan, nearbyint, nextafter, nexttoward, remainder, remquo, rint, round, scalbln, scanbn, tgamma, trunc -- float versions of the above, both as overloads and the same names ending in f -- long double versions of the above, both as overloads and the same names ending in l (lower-case L) -- additional overloads for the above so that any integer argument behaves the same as the version with a double argument, with the integer argument converted to double -- inline functions overloaded on float, double, and long double to replace the C99 function macros signbit, fpclassify, isfinite, isinf, isnan, isnormal, isgreater, isgreaterequal, isless, islessequal, islessgreater, isunordered EXISTING HEADERS and Add the function macro: va_copy(va_list) to copy a va_list object. HEADERS AND Add the headers and simply to define the macro: __bool_true_false_are_defined HEADERS and Add the headers and to define a number of integer properties. Specifically, the headers add a whole slew of macros, of the form: INT[FAST LEAST]{8 16 32 64}_MIN [U]INT[FAST LEAST]{8 16 32 64}_MAX INT{MAX PTR}_MIN [U]INT{MAX PTR}_MAX {SIG_ATOMIC WCHAR WINT}{_MAX _MIN} SIZE_MAX plus function macros (for converting literals to a known type) of the form: [U]INT{8 16 32 64}_C And they add a whole slew of types, of the form: [u]int[fast least]{8 16 32 64}_t [u]int{max ptr}_t EXISTING HEADERS AND Add the functions: snprintf vfprintf vprintf vsnprintf vprintf vfscanf vscanf vsscanf To the print and scan functions, add the conversion specifiers a (for hexadecimal floating-point) and F, and the conversion qualifiers hh, h, ll, t, and z (for various integer types). The scan functions should accept the various text forms of infinity and NaN values and the print functions should generate them. It is recommended that the num_get and num_put template classes also accept and generate the various text forms of infinity and NaN values. EXISTING HEADERS AND Add the type: lldiv_t Add the functions: atoll llabs lldiv strtof strtold strtoll strtoull _Exit And add the relevant long long overloads to: abs div HEADERS AND Add the headers and simply to include the headers (or ) and (or ). The generic capabilities added with C99 are already present in these other headers. EXISTING HEADERS AND Add the functions: wcstof wcstold wcstoll wcstoull EXISTING HEADERS AND Add the function: iswblank