delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/12/10/10:56:07

Date: Tue, 10 Dec 2002 15:56:06 +0000
From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
Sender: rich AT phekda DOT freeserve DOT co DOT uk
To: djgpp-workers AT delorie DOT com
X-Mailer: Emacs 21.3.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
Subject: <inttypes.h> (C99) [PATCH]
Message-Id: <E18Lmjh-00014N-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Please find below an implementation of <inttypes.h> and all its functions.
This is a new C99 header. I also found a bug in <stdint.h> - UINT8_MAX
is not defined.

The patch below requires my patch to scanf for the 'hh' conversion type
to have been applied. You may need to do a little manual merging
on src/docs/kb/wc204.txi, if you apply both my patches.

OK to commit? (The UINT8_MAX part is trivial. I will commit
that separately.)

Thanks, bye, Rich =]

Index: include/stdint.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/stdint.h,v
retrieving revision 1.2
diff -p -c -3 -r1.2 stdint.h
*** include/stdint.h	9 Feb 2001 11:11:41 -0000	1.2
--- include/stdint.h	10 Dec 2002 15:52:01 -0000
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
  /* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
  #ifndef __dj_stdint__h_
  #define __dj_stdint__h_
*************** __extension__ typedef unsigned long long
*** 46,51 ****
--- 47,53 ----
  #define INT_FAST8_MAX	 127
  #define UINT_FAST8_MAX	 255
  #define INT8_MAX	 127
+ #define UINT8_MAX	 255 
  #define INT_LEAST8_MIN	 (-128)
  #define INT_FAST8_MIN	 (-128)
  #define INT8_MIN	 (-128)
Index: src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.125
diff -p -c -3 -r1.125 wc204.txi
*** src/docs/kb/wc204.txi	6 Dec 2002 09:36:35 -0000	1.125
--- src/docs/kb/wc204.txi	10 Dec 2002 15:52:08 -0000
*************** This feature taken from a version of @co
*** 322,328 ****
  
  @cindex C99 compliance, new header files
  Header files, which are part of the new ANSI/ISO C99 Standard, are now
! available.  These include @file{stdint.h}.
  
  @cindex namespace @code{std} support
  When used in C AT t{++} programs, the standard C header files now make
--- 322,328 ----
  
  @cindex C99 compliance, new header files
  Header files, which are part of the new ANSI/ISO C99 Standard, are now
! available.  These include @file{stdint.h} and @file{inttypes.h}.
  
  @cindex namespace @code{std} support
  When used in C AT t{++} programs, the standard C header files now make
*************** The function @code{strtold} was added.
*** 794,798 ****
  
  @findex _doprnt AT r{, and }hh AT r{ conversion qualifier}
  @findex printf AT r{, and }hh AT r{ conversion qualifier}
! The @code{hh} conversion qualifier is now supported by @code{_doprnt}
! and the @code{printf} family of functions.
--- 794,811 ----
  
  @findex _doprnt AT r{, and }hh AT r{ conversion qualifier}
  @findex printf AT r{, and }hh AT r{ conversion qualifier}
! @findex _doscan AT r{, and }hh AT r{ conversion qualifier}
! @findex scanf AT r{, and }hh AT r{ conversion qualifier}
! The @code{hh} conversion qualifier is now supported by @code{_doprnt},
! @code{_doscan}, the @code{printf} family of functions
! and the @code{scanf} family of functions.
! 
! @findex imaxabs
! @findex imaxdiv
! @findex strtoimax
! @findex strtoumax
! @findex PRI
! @findex SCN
! The functions @code{imaxabs}, @code{imaxdiv}, @code{strtoimax}
! and @code{strtoumax} were added.  The @code{PRI} and @code{SCN} families
! of macros were added.
*** /dev/null	Tue Dec 10 15:52:47 2002
--- include/inttypes.h	Tue Dec 10 15:45:18 2002
***************
*** 0 ****
--- 1,203 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+ #include <stdint.h>
+ 
+ #ifndef __dj_inttypes__h_
+ #define __dj_inttypes__h_
+ 
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+ 
+ #ifndef __dj_ENFORCE_ANSI_FREESTANDING
+ 
+ #define PRId8       "hhd"
+ #define PRId16      "hd"
+ #define PRId32      "ld"
+ #define PRId64      "lld"
+ #define PRIdLEAST8  "hhd"
+ #define PRIdLEAST16 "hd"
+ #define PRIdLEAST32 "d"
+ #define PRIdLEAST64 "lld"
+ #define PRIdFAST8   "hhd"
+ #define PRIdFAST16  "d"
+ #define PRIdFAST32  "d"
+ #define PRIdFAST64  "lld"
+ #define PRIdMAX     "lld"
+ #define PRIdPTR     "ld"
+ 
+ #define PRIi8       "hhi"
+ #define PRIi16      "hi"
+ #define PRIi32      "li"
+ #define PRIi64      "lli"
+ #define PRIiLEAST8  "hhi"
+ #define PRIiLEAST16 "hi"
+ #define PRIiLEAST32 "i"
+ #define PRIiLEAST64 "lli"
+ #define PRIiFAST8   "hhi"
+ #define PRIiFAST16  "i"
+ #define PRIiFAST32  "i"
+ #define PRIiFAST64  "lli"
+ #define PRIiMAX     "lli"
+ #define PRIiPTR     "li"
+ 
+ #define PRIo8       "hho"
+ #define PRIo16      "ho"
+ #define PRIo32      "lo"
+ #define PRIo64      "llo"
+ #define PRIoLEAST8  "hho"
+ #define PRIoLEAST16 "ho"
+ #define PRIoLEAST32 "o"
+ #define PRIoLEAST64 "llo"
+ #define PRIoFAST8   "hho"
+ #define PRIoFAST16  "o"
+ #define PRIoFAST32  "o"
+ #define PRIoFAST64  "llo"
+ #define PRIoMAX     "llo"
+ #define PRIoPTR     "lo"
+ 
+ #define PRIu8       "hhu"
+ #define PRIu16      "hu"
+ #define PRIu32      "lu"
+ #define PRIu64      "llu"
+ #define PRIuLEAST8  "hhu"
+ #define PRIuLEAST16 "hu"
+ #define PRIuLEAST32 "u"
+ #define PRIuLEAST64 "llu"
+ #define PRIuFAST8   "hhu"
+ #define PRIuFAST16  "u"
+ #define PRIuFAST32  "u"
+ #define PRIuFAST64  "llu"
+ #define PRIuMAX     "llu"
+ #define PRIuPTR     "lu"
+ 
+ #define PRIx8       "hhx"
+ #define PRIx16      "hx"
+ #define PRIx32      "lx"
+ #define PRIx64      "llx"
+ #define PRIxLEAST8  "hhx"
+ #define PRIxLEAST16 "hx"
+ #define PRIxLEAST32 "x"
+ #define PRIxLEAST64 "llx"
+ #define PRIxFAST8   "hhx"
+ #define PRIxFAST16  "x"
+ #define PRIxFAST32  "x"
+ #define PRIxFAST64  "llx"
+ #define PRIxMAX     "llx"
+ #define PRIxPTR     "lx"
+ 
+ #define PRIX8       "hhX"
+ #define PRIX16      "hX"
+ #define PRIX32      "lX"
+ #define PRIX64      "llX"
+ #define PRIXLEAST8  "hhX"
+ #define PRIXLEAST16 "hX"
+ #define PRIXLEAST32 "X"
+ #define PRIXLEAST64 "llX"
+ #define PRIXFAST8   "hhX"
+ #define PRIXFAST16  "X"
+ #define PRIXFAST32  "X"
+ #define PRIXFAST64  "llX"
+ #define PRIXMAX     "llX"
+ #define PRIXPTR     "lX"
+ 
+ #define SCNd8       "hhd"
+ #define SCNd16      "hd"
+ #define SCNd32      "ld"
+ #define SCNd64      "lld"
+ #define SCNdLEAST8  "hhd"
+ #define SCNdLEAST16 "hd"
+ #define SCNdLEAST32 "d"
+ #define SCNdLEAST64 "lld"
+ #define SCNdFAST8   "hhd"
+ #define SCNdFAST16  "d"
+ #define SCNdFAST32  "d"
+ #define SCNdFAST64  "lld"
+ #define SCNdMAX     "lld"
+ #define SCNdPTR     "ld"
+ 
+ #define SCNi8       "hhi"
+ #define SCNi16      "hi"
+ #define SCNi32      "li"
+ #define SCNi64      "lli"
+ #define SCNiLEAST8  "hhi"
+ #define SCNiLEAST16 "hi"
+ #define SCNiLEAST32 "i"
+ #define SCNiLEAST64 "lli"
+ #define SCNiFAST8   "hhi"
+ #define SCNiFAST16  "i"
+ #define SCNiFAST32  "i"
+ #define SCNiFAST64  "lli"
+ #define SCNiMAX     "lli"
+ #define SCNiPTR     "li"
+ 
+ #define SCNo8       "hho"
+ #define SCNo16      "ho"
+ #define SCNo32      "lo"
+ #define SCNo64      "llo"
+ #define SCNoLEAST8  "hho"
+ #define SCNoLEAST16 "ho"
+ #define SCNoLEAST32 "o"
+ #define SCNoLEAST64 "llo"
+ #define SCNoFAST8   "hho"
+ #define SCNoFAST16  "o"
+ #define SCNoFAST32  "o"
+ #define SCNoFAST64  "llo"
+ #define SCNoMAX     "llo"
+ #define SCNoPTR     "lo"
+ 
+ #define SCNu8       "hhu"
+ #define SCNu16      "hu"
+ #define SCNu32      "lu"
+ #define SCNu64      "llu"
+ #define SCNuLEAST8  "hhu"
+ #define SCNuLEAST16 "hu"
+ #define SCNuLEAST32 "u"
+ #define SCNuLEAST64 "llu"
+ #define SCNuFAST8   "hhu"
+ #define SCNuFAST16  "u"
+ #define SCNuFAST32  "u"
+ #define SCNuFAST64  "llu"
+ #define SCNuMAX     "llu"
+ #define SCNuPTR     "lu"
+ 
+ #define SCNx8       "hhx"
+ #define SCNx16      "hx"
+ #define SCNx32      "lx"
+ #define SCNx64      "llx"
+ #define SCNxLEAST8  "hhx"
+ #define SCNxLEAST16 "hx"
+ #define SCNxLEAST32 "x"
+ #define SCNxLEAST64 "llx"
+ #define SCNxFAST8   "hhx"
+ #define SCNxFAST16  "x"
+ #define SCNxFAST32  "x"
+ #define SCNxFAST64  "llx"
+ #define SCNxMAX     "llx"
+ #define SCNxPTR     "lx"
+ 
+ typedef struct {
+   intmax_t quot;
+   intmax_t rem;
+ } imaxdiv_t;
+ 
+ intmax_t imaxabs (intmax_t _j);
+ imaxdiv_t imaxdiv (intmax_t _numer, intmax_t _denom);
+ intmax_t strtoimax (const char *_nptr, char **_endptr, int _base);
+ uintmax_t strtoumax (const char *_nptr, char **_endptr, int _base);
+ 
+ #ifndef __STRICT_ANSI__
+ 
+ #ifndef _POSIX_SOURCE
+ 
+ #endif /* !_POSIX_SOURCE */
+ #endif /* !__STRICT_ANSI__ */
+ #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
+ 
+ #ifndef __dj_ENFORCE_FUNCTION_CALLS
+ #endif /* !__dj_ENFORCE_FUNCTION_CALLS */
+ 
+ #ifdef __cplusplus
+ }
+ #endif
+ 
+ #endif /* __dj_inttypes__h_ */
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/makefile	Fri Nov 29 16:53:18 2002
***************
*** 0 ****
--- 1,9 ----
+ # Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details
+ TOP=../..
+ 
+ SRC += imaxabs.c
+ SRC += imaxdiv.c
+ SRC += strimax.c
+ SRC += strumax.c
+ 
+ include $(TOP)/../makefile.inc
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/.cvsignore	Tue Dec 10 14:26:58 2002
***************
*** 0 ****
--- 1,3 ----
+ *.d
+ *.oh
+ 
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/imaxabs.c	Thu Nov 28 12:43:18 2002
***************
*** 0 ****
--- 1,10 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+ #include <inttypes.h>
+ 
+ intmax_t
+ imaxabs (intmax_t j)
+ {
+   if (j < 0)
+     return(-j);
+   return(j);
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/imaxdiv.c	Thu Nov 28 12:42:30 2002
***************
*** 0 ****
--- 1,13 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+ #include <inttypes.h>
+ 
+ imaxdiv_t
+ imaxdiv (intmax_t numer, intmax_t denom)
+ {
+   imaxdiv_t res;
+ 
+   res.quot = numer / denom;
+   res.rem  = numer % denom;
+ 
+   return(res);
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/strimax.c	Thu Nov 28 16:46:52 2002
***************
*** 0 ****
--- 1,9 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+ #include <inttypes.h>
+ #include <stdlib.h>
+ 
+ intmax_t
+ strtoimax (const char *nptr, char **endptr, int base)
+ {
+   return(strtoll(nptr, endptr, base));
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/strumax.c	Thu Nov 28 16:46:36 2002
***************
*** 0 ****
--- 1,9 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
+ #include <inttypes.h>
+ #include <stdlib.h>
+ 
+ uintmax_t
+ strtoumax (const char *nptr, char **endptr, int base)
+ {
+   return(strtoull(nptr, endptr, base));
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/imaxabs.txh	Thu Nov 28 16:52:04 2002
***************
*** 0 ****
--- 1,20 ----
+ @node imaxabs, misc
+ @subheading Syntax
+ 
+ @example
+ #include <inttypes.h>
+ 
+ intmax_t imaxabs (intmax_t x);
+ @end example
+ 
+ @subheading Description
+ 
+ This function takes the absolute value of @var{x}.  @xref{abs}.
+ 
+ @subheading Return Value
+ 
+ |@var{x}|
+ 
+ @subheading Portability
+ 
+ @portability !ansi-c89, ansi-c99, !posix-1003.2-1992, posix-1003.1-2001
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/imaxdiv.txh	Thu Nov 28 16:55:00 2002
***************
*** 0 ****
--- 1,41 ----
+ @node imaxdiv, math
+ @subheading Syntax
+ 
+ @example
+ #include <inttypes.h>
+ 
+ imaxdiv_t imaxdiv (intmax_t numerator, intmax_t denominator);
+ @end example
+ 
+ @subheading Description
+ 
+ Returns the quotient and remainder of the division @var{numerator}
+ divided by @var{denominator}.  The return type is as follows:
+ 
+ @example
+ typedef struct @{
+   intmax_t quot;
+   intmax_t rem;
+ @} imaxdiv_t;
+ @end example
+ 
+ @subheading Return Value
+ 
+ The results of the division are returned.
+ 
+ @subheading Portability
+ 
+ @portability !ansi-c89, ansi-c99, !posix-1003.2-1992, posix-1003.1-2001
+ 
+ @subheading Example
+ 
+ @example
+ imaxdiv_t l = imaxdiv(42, 3);
+ printf("42 = %" PRIdMAX " x 3 + %" PRIdMAX "\n", l.quot, l.rem);
+ 
+ imaxdiv(+40, +3) = @{ +13, +1 @}
+ imaxdiv(+40, -3) = @{ -13, -1 @}
+ imaxdiv(-40, +3) = @{ -13, -1 @}
+ imaxdiv(-40, -3) = @{ +13, -1 @}
+ 
+ @end example
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/strimax.txh	Thu Nov 28 16:57:46 2002
***************
*** 0 ****
--- 1,37 ----
+ @node strtoimax, string
+ @subheading Syntax
+ 
+ @example
+ #include <inttypes.h>
+ 
+ intmax_t strtoimax (const char *s, char **endp, int base)
+ @end example
+ 
+ @subheading Description
+ 
+ This function converts as much of @var{s} as looks like an appropriate
+ number into the value of that number, and sets @var{*endp} to point to
+ the first unused character. 
+ 
+ The @var{base} argument indicates what base the digits (or letters)
+ should be treated as.  If @var{base} is zero, the base is determined by
+ looking for @code{0x}, @code{0X}, or @code{0} as the first part of the
+ string, and sets the base used to 16, 16, or 8 if it finds one.  The
+ default base is 10 if none of those prefixes are found.
+ 
+ @subheading Return Value
+ 
+ The value.
+ 
+ @subheading Portability
+ 
+ @portability !ansi-c89, ansi-c99, !posix-1003.2-1992, posix-1003.1-2001
+ 
+ @subheading Example
+ 
+ @example
+ printf("Enter a number: "); fflush(stdout);
+ gets(buf);
+ char *bp;
+ printf("The value is %" PRIdMAX "\n", strtoimax(buf, &bp, 0));
+ @end example
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/strumax.txh	Thu Nov 28 16:59:52 2002
***************
*** 0 ****
--- 1,30 ----
+ @node strtoumax, string
+ @subheading Syntax
+ 
+ @example
+ #include <inttypes.h>
+ 
+ uintmax_t strtoumax (const char *s, char **endp, int base);
+ @end example
+ 
+ @subheading Description
+ 
+ This is just like @code{strtoimax} (@pxref{strtoimax}) except that
+ the result is unsigned. 
+ 
+ @subheading Return Value
+ 
+ The value.
+ 
+ @subheading Portability
+ 
+ @portability !ansi-c89, ansi-c99, !posix-1003.2-1992, posix-1003.1-2001
+ 
+ @subheading Example
+ 
+ @example
+ printf("Enter a number: "); fflush(stdout);
+ gets(buf);
+ char *bp;
+ printf("The value is %" PRIuMAX "\n", strtoumax(buf, &bp, 0));
+ @end example
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/pri.txh	Tue Dec 10 15:03:36 2002
***************
*** 0 ****
--- 1,112 ----
+ @node PRI, stdio
+ @subheading Syntax
+ 
+ @example
+ #include <inttypes.h>
+ @end example
+ 
+ @subheading Description
+ 
+ The @code{PRI} family of macros allows integers to be displayed
+ in a portable manner using the @code{printf} family of functions
+ (@pxref{printf}).  They include a conversion qualifier, to specify
+ the width of the type (e.g.: @code{l} for @code{long}),
+ and the conversion type specifier (e.g.: @code{d} for decimal
+ display of integers).
+ 
+ The @code{PRI} family of macros should be used with the types defined
+ in the header @code{<stdint.h>}.  For example: @code{int8_t},
+ @code{uint_fast32_t}, @code{uintptr_t}, @code{intmax_t}.
+ 
+ Below N can be 8, 16, 32 or 64. The @code{PRI} macros are:
+ 
+ @table @code
+ 
+ @item PRIdN
+ @itemx PRIiN
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{intN_t} of N bits.
+ 
+ @item PRIdLEASTN
+ @itemx PRIiLEASTN
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{int_leastN_t} of N bits.
+ 
+ @item PRIdFASTN
+ @itemx PRIiFASTN
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{int_fastN_t} of N bits.
+ 
+ @item PRIdMAX
+ @itemx PRIiMAX
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{intmax_t}.
+ 
+ @item PRIdPTR
+ @itemx PRIiPTR
+ 
+ The @code{d} and @code{i} type conversion specifier
+ for a type @code{intptr_t}.
+ 
+ @item PRIoN
+ @itemx PRIuN
+ @itemx PRIxN
+ @itemx PRIXN
+ 
+ The @code{o}, @code{u}, @code{x} and @code{X} type conversion specifiers
+ for a type @code{uintN_t} of N bits.
+ 
+ @item PRIoLEASTN
+ @itemx PRIuLEASTN
+ @itemx PRIxLEASTN
+ @itemx PRIXLEASTN
+ 
+ The @code{o}, @code{u}, @code{x} and @code{X} type conversion specifiers
+ for a type @code{uint_LEASTN_t} of N bits.
+ 
+ @item PRIoFASTN
+ @itemx PRIuFASTN
+ @itemx PRIxFASTN
+ @itemx PRIXFASTN
+ 
+ The @code{o}, @code{u}, @code{x} and @code{X} type conversion specifiers
+ for a type @code{uint_FASTN_t} of N bits.
+ 
+ @item PRIoMAX
+ @itemx PRIuMAX
+ @itemx PRIxMAX
+ @itemx PRIXMAX
+ 
+ The @code{o}, @code{u}, @code{x} and @code{X} type conversion specifiers
+ for a type @code{uintmax_t}.
+ 
+ @item PRIoPTR
+ @itemx PRIuPTR
+ @itemx PRIxPTR
+ @itemx PRIXPTR
+ 
+ The @code{o}, @code{u}, @code{x} and @code{X} type conversion specifiers
+ for a type @code{uintptr_t}.
+ 
+ @end table
+ 
+ @subheading Return Value
+ 
+ Not applicable.
+ 
+ @subheading Portability
+ 
+ @portability !ansi-c89, ansi-c99, !posix-1003.2-1992, posix-1003.1-2001
+ 
+ @subheading Example
+ 
+ @example
+ uintmax_t foo = 500;
+ 
+ printf("foo is %" PRIuMAX " in decimal and 0x%" PRIxMAX " in hex.\n",
+        foo, foo);
+ @end example
*** /dev/null	Tue Dec 10 15:52:47 2002
--- src/libc/c99/inttypes/scn.txh	Tue Dec 10 15:03:12 2002
***************
*** 0 ****
--- 1,107 ----
+ @node SCN, stdio
+ @subheading Syntax
+ 
+ @example
+ #include <inttypes.h>
+ @end example
+ 
+ @subheading Description
+ 
+ The @code{SCN} family of macros allows integers to be input
+ in a portable manner using the @code{scanf} family of functions
+ (@pxref{scanf}).  They include a conversion qualifier, to specify
+ the width of the type (e.g.: @code{l} for @code{long}),
+ and the conversion type specifier (e.g.: @code{d} for decimal
+ display of integers).
+ 
+ The @code{SCN} family of macros should be used with the types defined
+ in the header @code{<stdint.h>}.  For example: @code{int8_t},
+ @code{uint_fast32_t}, @code{uintptr_t}, @code{intmax_t}.
+ 
+ Below N can be 8, 16, 32 or 64. The @code{SCN} macros are:
+ 
+ @table @code
+ 
+ @item SCNdN
+ @itemx SCNiN
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{intN_t} of N bits.
+ 
+ @item SCNdLEASTN
+ @itemx SCNiLEASTN
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{int_leastN_t} of N bits.
+ 
+ @item SCNdFASTN
+ @itemx SCNiFASTN
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{int_fastN_t} of N bits.
+ 
+ @item SCNdMAX
+ @itemx SCNiMAX
+ 
+ The @code{d} and @code{i} type conversion specifiers
+ for a type @code{intmax_t}.
+ 
+ @item SCNdPTR
+ @itemx SCNiPTR
+ 
+ The @code{d} and @code{i} type conversion specifier
+ for a type @code{intptr_t}.
+ 
+ @item SCNoN
+ @itemx SCNuN
+ @itemx SCNxN
+ 
+ The @code{o}, @code{u} and @code{x} type conversion specifiers
+ for a type @code{uintN_t} of N bits.
+ 
+ @item SCNoLEASTN
+ @itemx SCNuLEASTN
+ @itemx SCNxLEASTN
+ 
+ The @code{o}, @code{u} and @code{x} type conversion specifiers
+ for a type @code{uint_LEASTN_t} of N bits.
+ 
+ @item SCNoFASTN
+ @itemx SCNuFASTN
+ @itemx SCNxFASTN
+ 
+ The @code{o}, @code{u} and @code{x} type conversion specifiers
+ for a type @code{uint_FASTN_t} of N bits.
+ 
+ @item SCNoMAX
+ @itemx SCNuMAX
+ @itemx SCNxMAX
+ 
+ The @code{o}, @code{u} and @code{x} type conversion specifiers
+ for a type @code{uintmax_t}.
+ 
+ @item SCNoPTR
+ @itemx SCNuPTR
+ @itemx SCNxPTR
+ 
+ The @code{o}, @code{u} and @code{x} type conversion specifiers
+ for a type @code{uintptr_t}.
+ 
+ @end table
+ 
+ @subheading Return Value
+ 
+ Not applicable.
+ 
+ @subheading Portability
+ 
+ @portability !ansi-c89, ansi-c99, !posix-1003.2-1992, posix-1003.1-2001
+ 
+ @subheading Example
+ 
+ @example
+ intmax_t m;
+ int ret;
+ 
+ ret = sscanf("0x1000", "%" SCNxMAX, &m);
+ @end example
*** /dev/null	Tue Dec 10 15:52:47 2002
--- tests/libc/c99/inttypes/makefile	Tue Dec 10 15:05:18 2002
***************
*** 0 ****
--- 1,9 ----
+ TOP=../..
+ 
+ SRC += t-imxabs.c
+ SRC += t-imxdiv.c
+ SRC += t-priscn.c
+ SRC += t-strimx.c
+ SRC += t-strumx.c
+ 
+ include $(TOP)/../makefile.inc
*** /dev/null	Tue Dec 10 15:52:47 2002
--- tests/libc/c99/inttypes/.cvsignore	Sat Nov 30 13:24:40 2002
***************
*** 0 ****
--- 1 ----
+ *.d
*** /dev/null	Tue Dec 10 15:52:47 2002
--- tests/libc/c99/inttypes/t-imxabs.c	Sat Nov 30 13:38:02 2002
***************
*** 0 ****
--- 1,17 ----
+ #include <assert.h>
+ #include <inttypes.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ 
+ int
+ main (void)
+ {
+   const intmax_t i = INTMAX_MAX;
+   const intmax_t j = -INTMAX_MAX;
+ 
+   assert(imaxabs(i) == i);
+   assert(imaxabs(j) == -j);
+ 
+   puts("PASS");
+   return(EXIT_SUCCESS);
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- tests/libc/c99/inttypes/t-imxdiv.c	Sat Nov 30 13:52:56 2002
***************
*** 0 ****
--- 1,28 ----
+ #include <assert.h>
+ #include <inttypes.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ 
+ int
+ main (void)
+ {
+   intmax_t  n, d;
+   imaxdiv_t res;
+ 
+   /* See <stdint.h>: INTMAX_MAX is an odd number. */
+ 
+   n = INTMAX_MAX;
+   d = 1;
+   res = imaxdiv(n, d);
+   assert(res.quot == n);
+   assert(res.rem  == 0);
+ 
+   n = INTMAX_MAX;
+   d = 2;
+   res = imaxdiv(n, d);
+   assert(res.quot == (n / 2));
+   assert(res.rem  == 1);
+ 
+   puts("PASS");
+   return(EXIT_SUCCESS);
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- tests/libc/c99/inttypes/t-priscn.c	Tue Dec 10 15:37:50 2002
***************
*** 0 ****
--- 1,147 ----
+ #include <assert.h>
+ #include <inttypes.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ #define TEST_T(x) \
+ typedef struct { \
+   const int ##x ##_t n; \
+   int ##x ##_t d_res; \
+   int ##x ##_t i_res; \
+ } test_int ##x ##_t
+ 
+ #define TEST_U_T(x) \
+ typedef struct { \
+   const uint ##x ##_t n; \
+   uint ##x ##_t o_res; \
+   uint ##x ##_t u_res; \
+   uint ##x ##_t x_res; \
+   uint ##x ##_t X_res; \
+ } test_uint ##x ##_t
+ 
+ TEST_T(8);
+ TEST_T(16);
+ TEST_T(32);
+ TEST_T(64);
+ 
+ TEST_T(_fast8);
+ TEST_T(_fast16);
+ TEST_T(_fast32);
+ TEST_T(_fast64);
+ 
+ TEST_T(_least8);
+ TEST_T(_least16);
+ TEST_T(_least32);
+ TEST_T(_least64);
+ 
+ TEST_T(max);
+ TEST_T(ptr);
+ 
+ TEST_U_T(8);
+ TEST_U_T(16);
+ TEST_U_T(32);
+ TEST_U_T(64);
+ 
+ TEST_U_T(_fast8);
+ TEST_U_T(_fast16);
+ TEST_U_T(_fast32);
+ TEST_U_T(_fast64);
+ 
+ TEST_U_T(_least8);
+ TEST_U_T(_least16);
+ TEST_U_T(_least32);
+ TEST_U_T(_least64);
+ 
+ TEST_U_T(max);
+ TEST_U_T(ptr);
+ 
+ #undef TEST_T
+ #undef TEST_U_T
+ 
+ #define TEST(x, y, z) \
+   { \
+     char buf[128]; \
+     test_int ##x ##_t t = { INT ##y ##_MAX, 0, 0 }; \
+     int ret; \
+ \
+     sprintf(buf, "%" PRId ##z, t.n); \
+     ret = sscanf(buf, "%" SCNd ##z, &t.d_res); \
+     assert(ret > 0); \
+     assert(t.d_res == t.n); \
+ \
+     sprintf(buf, "%" PRIi ##z, t.n); \
+     ret = sscanf(buf, "%" SCNi##z, &t.i_res); \
+     assert(ret > 0); \
+     assert(t.i_res == t.n); \
+   }
+ 
+ #define TEST_U(x, y, z) \
+   { \
+     char buf[128]; \
+     test_uint ##x ##_t t = { UINT ##y ##_MAX, 0, 0 }; \
+     int ret; \
+ \
+     sprintf(buf, "%" PRIu ##z, t.n); \
+     ret = sscanf(buf, "%" SCNu ##z, &t.u_res); \
+     assert(ret > 0); \
+     assert(t.u_res == t.n); \
+ \
+     sprintf(buf, "%" PRIo ##z, t.n); \
+     ret = sscanf(buf, "%" SCNo ##z, &t.o_res); \
+     assert(ret > 0); \
+     assert(t.o_res == t.n); \
+ \
+     sprintf(buf, "%" PRIx ##z, t.n); \
+     ret = sscanf(buf, "%" SCNx ##z, &t.x_res); \
+     assert(ret > 0); \
+     assert(t.x_res == t.n); \
+ \
+     sprintf(buf, "%" PRIX ##z, t.n); \
+     ret = sscanf(buf, "%" SCNx ##z, &t.X_res); \
+     assert(ret > 0); \
+     assert(t.X_res == t.n); \
+   }
+ 
+ int
+ main (void)
+ {
+   TEST(8,  8,  8);
+   TEST(16, 16, 16);
+   TEST(32, 32, 32);
+   TEST(64, 64, 64);
+ 
+   TEST(_fast8,  _FAST8,  FAST8);
+   TEST(_fast16, _FAST16, FAST16);
+   TEST(_fast32, _FAST32, FAST32);
+   TEST(_fast64, _FAST64, FAST64);
+ 
+   TEST(_least8,  _LEAST8,  LEAST8);
+   TEST(_least16, _LEAST16, LEAST16);
+   TEST(_least32, _LEAST32, LEAST32);
+   TEST(_least64, _LEAST64, LEAST64);
+ 
+   TEST(max, MAX, MAX);
+   TEST(ptr, PTR, PTR);
+ 
+   TEST_U(8,  8,  8);
+   TEST_U(16, 16, 16);
+   TEST_U(32, 32, 32);
+   TEST_U(64, 64, 64);
+ 
+   TEST_U(_fast8,  _FAST8,  FAST8);
+   TEST_U(_fast16, _FAST16, FAST16);
+   TEST_U(_fast32, _FAST32, FAST32);
+   TEST_U(_fast64, _FAST64, FAST64);
+ 
+   TEST_U(_least8,  _LEAST8,  LEAST8);
+   TEST_U(_least16, _LEAST16, LEAST16);
+   TEST_U(_least32, _LEAST32, LEAST32);
+   TEST_U(_least64, _LEAST64, LEAST64);
+ 
+   TEST_U(max, MAX, MAX);
+   TEST_U(ptr, PTR, PTR);
+ 
+   puts("PASS");
+   return(EXIT_SUCCESS);
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- tests/libc/c99/inttypes/t-strimx.c	Sat Nov 30 13:41:40 2002
***************
*** 0 ****
--- 1,52 ----
+ #include <assert.h>
+ #include <inttypes.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ int
+ main (void)
+ {
+   const intmax_t  i = INTMAX_MAX;
+   const intmax_t  j = INTMAX_MIN;
+   intmax_t        res;
+   char            buf[64];
+   char           *p = NULL;
+ 
+   /* Positive number */
+   sprintf(buf, "%" PRIdMAX, i);
+   res = strtoimax(buf, &p, 0);
+   assert(res == i);
+ 
+   sprintf(buf, "%" PRIdMAX, i);
+   res = strtoimax(buf, &p, 10);
+   assert(res == i);
+ 
+   sprintf(buf, "%" PRIiMAX, i);
+   res = strtoimax(buf, &p, 0);
+   assert(res == i);
+ 
+   sprintf(buf, "%" PRIiMAX, i);
+   res = strtoimax(buf, &p, 10);
+   assert(res == i);
+ 
+   /* Negative number */
+   sprintf(buf, "%" PRIdMAX, j);
+   res = strtoimax(buf, &p, 0);
+   assert(res == j);
+ 
+   sprintf(buf, "%" PRIdMAX, j);
+   res = strtoimax(buf, &p, 10);
+   assert(res == j);
+ 
+   sprintf(buf, "%" PRIiMAX, j);
+   res = strtoimax(buf, &p, 0);
+   assert(res == j);
+ 
+   sprintf(buf, "%" PRIiMAX, j);
+   res = strtoimax(buf, &p, 10);
+   assert(res == j);
+ 
+   puts("PASS");
+   return(EXIT_SUCCESS);
+ }
*** /dev/null	Tue Dec 10 15:52:47 2002
--- tests/libc/c99/inttypes/t-strumx.c	Sat Nov 30 13:42:18 2002
***************
*** 0 ****
--- 1,37 ----
+ #include <assert.h>
+ #include <inttypes.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
+ 
+ int
+ main (void)
+ {
+   const uintmax_t i = UINTMAX_MAX;
+   intmax_t        res;
+   char            buf[64];
+   char           *p = NULL;
+ 
+   sprintf(buf, "%" PRIuMAX, i);
+   res = strtoumax(buf, &p, 0);
+   assert(res == i);
+ 
+   sprintf(buf, "%" PRIuMAX, i);
+   res = strtoumax(buf, &p, 10);
+   assert(res == i);
+ 
+   sprintf(buf, "%" PRIoMAX, i);
+   res = strtoumax(buf, &p, 0);
+   assert(res == i);
+ 
+   sprintf(buf, "0x%" PRIxMAX, i);
+   res = strtoumax(buf, &p, 0);
+   assert(res == i);
+ 
+   sprintf(buf, "0x%" PRIXMAX, i);
+   res = strtoumax(buf, &p, 0);
+   assert(res == i);
+ 
+   puts("PASS");
+   return(EXIT_SUCCESS);
+ }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019