aboutsummaryrefslogtreecommitdiff
path: root/manual
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2016-09-19 12:25:36 +0000
committerJoseph Myers <joseph@codesourcery.com>2016-09-19 12:25:36 +0000
commita292f45acdf0a35266e4f1dd1e51b95ca5325d2a (patch)
treef687d1f62b0aa8975876aae0025569e103845df1 /manual
parent455d6e4373c81da49892d39f33dc312b0c54097d (diff)
downloadglibc-a292f45acdf0a35266e4f1dd1e51b95ca5325d2a.zip
glibc-a292f45acdf0a35266e4f1dd1e51b95ca5325d2a.tar.gz
glibc-a292f45acdf0a35266e4f1dd1e51b95ca5325d2a.tar.bz2
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 'manual')
-rw-r--r--manual/lang.texi50
1 files changed, 50 insertions, 0 deletions
diff --git a/manual/lang.texi b/manual/lang.texi
index 7f8a368..3705df0 100644
--- a/manual/lang.texi
+++ b/manual/lang.texi
@@ -653,6 +653,56 @@ sizeof (@var{type}) * CHAR_BIT
@end smallexample
@end table
+That expression includes padding bits as well as value and sign bits.
+On all systems supported by @theglibc{}, standard integer types other
+than @code{_Bool} do not have any padding bits. TS 18661-1:2014
+defines additional macros for the width of integer types (the number
+of value and sign bits); these macros can also be used in @code{#if}
+preprocessor directives, whereas @code{sizeof} cannot. The following
+macros are defined in @file{limits.h}.
+
+@table @code
+@comment limits.h
+@comment ISO
+@item CHAR_WIDTH
+@comment limits.h
+@comment ISO
+@itemx SCHAR_WIDTH
+@comment limits.h
+@comment ISO
+@itemx UCHAR_WIDTH
+@comment limits.h
+@comment ISO
+@itemx SHRT_WIDTH
+@comment limits.h
+@comment ISO
+@itemx USHRT_WIDTH
+@comment limits.h
+@comment ISO
+@itemx INT_WIDTH
+@comment limits.h
+@comment ISO
+@itemx UINT_WIDTH
+@comment limits.h
+@comment ISO
+@itemx LONG_WIDTH
+@comment limits.h
+@comment ISO
+@itemx ULONG_WIDTH
+@comment limits.h
+@comment ISO
+@itemx LLONG_WIDTH
+@comment limits.h
+@comment ISO
+@itemx ULLONG_WIDTH
+
+These are the widths of the types @code{char}, @code{signed char},
+@code{unsigned char}, @code{short int}, @code{unsigned short int},
+@code{int}, @code{unsigned int}, @code{long int}, @code{unsigned long
+int}, @code{long long int} and @code{unsigned long long int},
+respectively.
+@end table
+
@node Range of Type
@subsection Range of an Integer Type
@cindex integer type range