diff options
author | Joseph Myers <joseph@codesourcery.com> | 2016-09-19 12:25:36 +0000 |
---|---|---|
committer | Joseph Myers <joseph@codesourcery.com> | 2016-09-19 12:25:36 +0000 |
commit | a292f45acdf0a35266e4f1dd1e51b95ca5325d2a (patch) | |
tree | f687d1f62b0aa8975876aae0025569e103845df1 /include/limits.h | |
parent | 455d6e4373c81da49892d39f33dc312b0c54097d (diff) | |
download | glibc-a292f45acdf0a35266e4f1dd1e51b95ca5325d2a.tar.gz glibc-a292f45acdf0a35266e4f1dd1e51b95ca5325d2a.tar.xz glibc-a292f45acdf0a35266e4f1dd1e51b95ca5325d2a.zip |
Add <limits.h> integer width macros.
TS 18661-1 defines macros for the width of integer types, intended for use with the fromfp functions to convert from floating-point types to integer types of any width, in any rounding mode and with control over whether "inexact" is raised. Such macros are, of course, more generally useful than just with those functions. Those macros are added to <limits.h> and <stdint.h>. This patch adds the <limits.h> macros to glibc's header, with the <stdint.h> ones intended to be added in a separate patch (which would add to the NEWS entry created by this patch). I've also added these macros to GCC's headers for GCC 7, but definitions in glibc's <limits.h> are still useful for older GCC, for non-GNU compilers and for when it's _GNU_SOURCE rather than __STDC_WANT_IEC_60559_BFP_EXT__ that implies the macros should be defined since the GCC header only considers __STDC_WANT_IEC_60559_BFP_EXT__ (and for glibc systems, the definitions in GCC's <stdint.h> will only be used with -ffreestanding). Tested for x86_64 and x86. * include/limits.h: Define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION and include <bits/libc-header-start.h> instead of including <features.h>. [__GLIBC_USE (IEC_60559_BFP_EXT)] (CHAR_WIDTH): New macro. [__GLIBC_USE (IEC_60559_BFP_EXT)] (SCHAR_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (UCHAR_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (SHRT_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (USHRT_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (INT_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (UINT_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (LONG_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (ULONG_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (LLONG_WIDTH): Likewise. [__GLIBC_USE (IEC_60559_BFP_EXT)] (ULLONG_WIDTH): Likewise. * manual/lang.texi (Width of Type): Document these macros. * stdlib/tst-width.c: New file. * stdlib/Makefile (tests): Add tst-width.
Diffstat (limited to 'include/limits.h')
-rw-r--r-- | include/limits.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/include/limits.h b/include/limits.h index 5add8fceb9..93cac49e55 100644 --- a/include/limits.h +++ b/include/limits.h @@ -22,7 +22,8 @@ #ifndef _LIBC_LIMITS_H_ #define _LIBC_LIMITS_H_ 1 -#include <features.h> +#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION +#include <bits/libc-header-start.h> /* Maximum length of any multibyte character in any locale. @@ -138,6 +139,54 @@ # endif #endif +/* The integer width macros are not defined by GCC's <limits.h> before + GCC 7, or if _GNU_SOURCE rather than + __STDC_WANT_IEC_60559_BFP_EXT__ is used to enable this feature. */ +#if __GLIBC_USE (IEC_60559_BFP_EXT) +# ifndef CHAR_WIDTH +# define CHAR_WIDTH 8 +# endif +# ifndef SCHAR_WIDTH +# define SCHAR_WIDTH 8 +# endif +# ifndef UCHAR_WIDTH +# define UCHAR_WIDTH 8 +# endif +# ifndef SHRT_WIDTH +# define SHRT_WIDTH 16 +# endif +# ifndef USHRT_WIDTH +# define USHRT_WIDTH 16 +# endif +# ifndef INT_WIDTH +# define INT_WIDTH 32 +# endif +# ifndef UINT_WIDTH +# define UINT_WIDTH 32 +# endif +# if LONG_MAX == 0x7fffffffL +# ifndef LONG_WIDTH +# define LONG_WIDTH 32 +# endif +# ifndef ULONG_WIDTH +# define ULONG_WIDTH 32 +# endif +# else +# ifndef LONG_WIDTH +# define LONG_WIDTH 64 +# endif +# ifndef ULONG_WIDTH +# define ULONG_WIDTH 64 +# endif +# endif +# ifndef LLONG_WIDTH +# define LLONG_WIDTH 64 +# endif +# ifndef ULLONG_WIDTH +# define ULLONG_WIDTH 64 +# endif +#endif /* Use IEC_60559_BFP_EXT. */ + #ifdef __USE_POSIX /* POSIX adds things to <limits.h>. */ # include <bits/posix1_lim.h> |