stdint.h

Corinna Vinschen vinschen@redhat.com
Tue Sep 20 10:23:00 GMT 2005


Guys,

On Sep 20 00:25, Christopher Faylor wrote:
> On Tue, Sep 20, 2005 at 04:47:27AM +0200, Ralf Corsepius wrote:
> >On Mon, 2005-09-19 at 22:11 -0400, Christopher Faylor wrote:
> >>I really don't see any need to use the RTEMS stuff especially given the
> >>"it's not broke" principle.
> >
> >Well, the RTEMS stdint.h/inttypes.h aren't specific to RTEMS.
> 
> Again, since there is nothing wrong with the present cygwin
> implementation, there is no reason to change what we have.

First, Jeff, would you mind to wait a few hours before changing stuff
which affects all targets like that?  The whole process of checkin plus
discussion took place in one single night from my timezone's point of view.

I was going to be a bit more relaxed about this issue than Chris, so
I created a thorough testcase to check how this affects Cygwin.  The
attached, very simple testcase builds and runs fine using Cygwin's
stdint.h/inttypes.h.  FWIW, the same testcase runs fine on Linux with
glibc.

However, it doesn't even build when using RTMES stdint.h/inttypes.h,
so I don't think the RTEMS stdint.h was ready for prime time:

- All *fast* typedefs are missing (int_fast8_t, etc.) and all
  *FAST* definitions (INT_FAST8_MIN, etc.) are missing.

   This is marked as "todo" in the header comment.

- A couple of disturbing warnings about INT32_MIN, INT64_MIN, INT64_MAX
  and the corresponding unsigned defnitions:

   INT32_MIN:  warning: this decimal constant is unsigned only in ISO C90
   INT64_MIN:  integer constant is so large that it is unsigned
               this decimal constant is unsigned only in ISO C90
   INT64_MAX:  integer constant is too large for "long" type
   UINT32_MAX: warning: this decimal constant is unsigned only in ISO C90
   UINT64_MAX: warning: integer constant is so large that it is unsigned
               warning: this decimal constant is unsigned only in ISO C90
	       warning: integer constant is too large for "long" type

  When uncommenting every other problem in the file, there's also a bug
  in evaluating the INT32*_MIN values:

    INT32_MIN, INTLEAST32_MIN are printed as the positive value
    2147483648, not -2147483648.

- All *LEAST* definitions are incorrect because RTEMS' stdint.h defines
  them omitting an underscore after the type:

    RTEMS:  INTLEAST8_MIN
    SUSv3:  INT_LEAST8_MIN

- All INTPTR* definitions are missing (INTPTR_MIN, INTPTR_MAX, UINTPTR_MAX).

- All INTMAX* definitions are missing (INTMAX_MIN, INTMAX_MAX, UINTMAX_MAX).

- The condition, when to include limits.h and when not to include it,
  seems not to be foolproof.  I get these error message as well, unless
  I manually include limits.h prior to including inttypes.h:

    stdint-test.c:296: error: `LONG_MAX' undeclared here (not in a function)
    stdint-test.c:299: error: `INT_MAX' undeclared here (not in a function)

- Definitions of PTRDIFF_MIN and PTRDIFF_MAX are missing.

- Definitions for WCHAR_MIN, WCHAR_MAX, WINT_MIN, WINT_MAX are missing.

    The missing WINT macros are marked as "todo" in the header comment.

I didn't check if all PRI* and SCN* definitions have the right value, though.


Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat, Inc.
-------------- next part --------------
#include <stdio.h>
#include <inttypes.h>

char *arr1[] = {
  PRId8,
  PRId16,
  PRId32,
  PRId64,

  PRIdLEAST8,
  PRIdLEAST16,
  PRIdLEAST32,
  PRIdLEAST64,

  PRIdFAST8,
  PRIdFAST16,
  PRIdFAST32,
  PRIdFAST64,

  PRIdMAX,
  PRIdPTR,

  PRIi8,
  PRIi16,
  PRIi32,
  PRIi64,

  PRIiLEAST8,
  PRIiLEAST16,
  PRIiLEAST32,
  PRIiLEAST64,

  PRIiFAST8,
  PRIiFAST16,
  PRIiFAST32,
  PRIiFAST64,

  PRIiMAX,
  PRIiPTR,

/* fprintf() macros for unsigned integers */

  PRIo8,
  PRIo16,
  PRIo32,
  PRIo64,

  PRIoLEAST8,
  PRIoLEAST16,
  PRIoLEAST32,
  PRIoLEAST64,

  PRIoFAST8,
  PRIoFAST16,
  PRIoFAST32,
  PRIoFAST64,

  PRIoMAX,
  PRIoPTR,

  PRIu8,
  PRIu16,
  PRIu32,
  PRIu64,

  PRIuLEAST8,
  PRIuLEAST16,
  PRIuLEAST32,
  PRIuLEAST64,

  PRIuFAST8,
  PRIuFAST16,
  PRIuFAST32,
  PRIuFAST64,

  PRIuMAX,
  PRIuPTR,

  PRIx8,
  PRIx16,
  PRIx32,
  PRIx64,

  PRIxLEAST8,
  PRIxLEAST16,
  PRIxLEAST32,
  PRIxLEAST64,

  PRIxFAST8,
  PRIxFAST16,
  PRIxFAST32,
  PRIxFAST64,

  PRIxMAX,
  PRIxPTR,

  PRIX8,
  PRIX16,
  PRIX32,
  PRIX64,

  PRIXLEAST8,
  PRIXLEAST16,
  PRIXLEAST32,
  PRIXLEAST64,

  PRIXFAST8,
  PRIXFAST16,
  PRIXFAST32,
  PRIXFAST64,

  PRIXMAX,
  PRIXPTR,

/* fscanf() macros for signed integers */

  SCNd8,
  SCNd16,
  SCNd32,
  SCNd64,

  SCNdLEAST8,
  SCNdLEAST16,
  SCNdLEAST32,
  SCNdLEAST64,

  SCNdFAST8,
  SCNdFAST16,
  SCNdFAST32,
  SCNdFAST64,

  SCNdMAX,
  SCNdPTR,

  SCNi8,
  SCNi16,
  SCNi32,
  SCNi64,

  SCNiLEAST8,
  SCNiLEAST16,
  SCNiLEAST32,
  SCNiLEAST64,

  SCNiFAST8,
  SCNiFAST16,
  SCNiFAST32,
  SCNiFAST64,

  SCNiMAX,
  SCNiPTR,

/* fscanf() macros for unsigned integers */

  SCNo8,
  SCNo16,
  SCNo32,
  SCNo64,

  SCNoLEAST8,
  SCNoLEAST16,
  SCNoLEAST32,
  SCNoLEAST64,

  SCNoFAST8,
  SCNoFAST16,
  SCNoFAST32,
  SCNoFAST64,

  SCNoMAX,
  SCNoPTR,

  SCNu8,
  SCNu16,
  SCNu32,
  SCNu64,

  SCNuLEAST8,
  SCNuLEAST16,
  SCNuLEAST32,
  SCNuLEAST64,

  SCNuFAST8,
  SCNuFAST16,
  SCNuFAST32,
  SCNuFAST64,

  SCNuMAX,
  SCNuPTR,

  SCNx8,
  SCNx16,
  SCNx32,
  SCNx64,

  SCNxLEAST8,
  SCNxLEAST16,
  SCNxLEAST32,
  SCNxLEAST64,

  SCNxFAST8,
  SCNxFAST16,
  SCNxFAST32,
  SCNxFAST64,

  SCNxMAX,
  SCNxPTR,
  NULL
};

int arr2[] = {
  sizeof (wchar_t),
  sizeof (int8_t),
  sizeof (int16_t),
  sizeof (int32_t),
  sizeof (int64_t),

  sizeof (uint8_t),
  sizeof (uint16_t),
  sizeof (uint32_t),
  sizeof (uint64_t),

/* Minimum-width integer types */

  sizeof (int_least8_t),
  sizeof (int_least16_t),
  sizeof (int_least32_t),
  sizeof (int_least64_t),

  sizeof (uint_least8_t),
  sizeof (uint_least16_t),
  sizeof (uint_least32_t),
  sizeof (uint_least64_t),

/* Fastest minimum-width integer types */

  sizeof (int_fast8_t),
  sizeof (int_fast16_t),
  sizeof (int_fast32_t),
  sizeof (int_fast64_t),

  sizeof (uint_fast8_t),
  sizeof (uint_fast16_t),
  sizeof (uint_fast32_t),
  sizeof (uint_fast64_t),

/* Integer types capable of holding object pointers */

  sizeof (intptr_t),
  sizeof (uintptr_t),

/* Greatest-width integer types */

  sizeof (intmax_t),
  sizeof (uintmax_t),
  0
};

long long arr3[] = {
  INT8_MIN,
  INT16_MIN,
  INT32_MIN,
  INT64_MIN,

  INT8_MAX,
  INT16_MAX,
  INT32_MAX,
  INT64_MAX,

  INT_LEAST8_MIN,
  INT_LEAST16_MIN,
  INT_LEAST32_MIN,
  INT_LEAST64_MIN,

  INT_LEAST8_MAX,
  INT_LEAST16_MAX,
  INT_LEAST32_MAX,
  INT_LEAST64_MAX,

  INT_FAST8_MIN,
  INT_FAST16_MIN,
  INT_FAST32_MIN,
  INT_FAST64_MIN,

  INT_FAST8_MAX,
  INT_FAST16_MAX,
  INT_FAST32_MAX,
  INT_FAST64_MAX,

  INTPTR_MIN,
  INTPTR_MAX,

  INTMAX_MIN,
  INTMAX_MAX,

  PTRDIFF_MIN,
  PTRDIFF_MAX,

  SIG_ATOMIC_MAX,

  WINT_MIN,
  WINT_MAX,

  WCHAR_MAX,
  WCHAR_MIN,	/* Last element since it may be 0. */
  0
};

unsigned long long arr4[] = {
  UINT8_MAX,
  UINT16_MAX,
  UINT32_MAX,
  UINT64_MAX,

  UINT_LEAST8_MAX,
  UINT_LEAST16_MAX,
  UINT_LEAST32_MAX,
  UINT_LEAST64_MAX,

  UINT_FAST8_MAX,
  UINT_FAST16_MAX,
  UINT_FAST32_MAX,
  UINT_FAST64_MAX,

  UINTPTR_MAX,

  UINTMAX_MAX,

  SIZE_MAX,
  0
};

int
main ()
{
  int i;

  for (i = 0; arr1[i]; ++i)
    printf ("%s\n", arr1[i]);
  for (i = 0; arr2[i]; ++i)
    printf ("%d\n", arr2[i]);
  for (i = 0; arr3[i]; ++i)
    printf ("%lld\n", arr3[i]);
  for (i = 0; arr4[i]; ++i)
    printf ("%llu\n", arr4[i]);
  return 0;
}


More information about the Newlib mailing list