Add iso646.h, stdint.h, and inttypes.h headers.

These mostly comply with C99 and C11, with some exceptions noted in comments.
This commit is contained in:
Stephen Heumann 2017-10-21 20:40:41 -05:00
parent a69fc2be59
commit 9d018cafe7
3 changed files with 333 additions and 0 deletions

170
ORCACDefs/inttypes.h Normal file
View File

@ -0,0 +1,170 @@
/****************************************************************
*
* inttypes.h - format conversion of integer types
*
* September 2017
* Stephen Heumann
*
****************************************************************/
/*
* Note: The format specifier macros defined here generally comply with the
* C99 and C11 standards, except that those associated with intmax_t and
* uintmax_t correspond to their non-standard definitions as 32-bit types.
* fscanf macros for 8-bit types are not defined because ORCA/C's fscanf
* implementation currently does not support them. The functions that the
* standards specify should be declared in this header are also not available.
*/
#ifndef __inttypes__
#define __inttypes__
#include <stdint.h>
/* fprintf macros for signed integers */
#define PRId8 "d" /* int8_t */
#define PRId16 "d" /* int16_t */
#define PRId32 "ld" /* int32_t */
#define PRIdLEAST8 "d" /* int_least8_t */
#define PRIdLEAST16 "d" /* int_least16_t */
#define PRIdLEAST32 "ld" /* int_least32_t */
#define PRIdFAST8 "d" /* int_fast8_t */
#define PRIdFAST16 "d" /* int_fast16_t */
#define PRIdFAST32 "ld" /* int_fast32_t */
#define PRIdMAX "ld" /* intmax_t */
#define PRIdPTR "ld" /* intptr_t */
#define PRIi8 "i" /* int8_t */
#define PRIi16 "i" /* int16_t */
#define PRIi32 "li" /* int32_t */
#define PRIiLEAST8 "i" /* int_least8_t */
#define PRIiLEAST16 "i" /* int_least16_t */
#define PRIiLEAST32 "li" /* int_least32_t */
#define PRIiFAST8 "i" /* int_fast8_t */
#define PRIiFAST16 "i" /* int_fast16_t */
#define PRIiFAST32 "li" /* int_fast32_t */
#define PRIiMAX "li" /* intmax_t */
#define PRIiPTR "li" /* intptr_t */
/* fprintf macros for unsigned integers */
#define PRIo8 "o" /* uint8_t */
#define PRIo16 "o" /* uint16_t */
#define PRIo32 "lo" /* uint32_t */
#define PRIoLEAST8 "o" /* uint_least8_t */
#define PRIoLEAST16 "o" /* uint_least16_t */
#define PRIoLEAST32 "lo" /* uint_least32_t */
#define PRIoFAST8 "o" /* uint_fast8_t */
#define PRIoFAST16 "o" /* uint_fast16_t */
#define PRIoFAST32 "lo" /* uint_fast32_t */
#define PRIoMAX "lo" /* uintmax_t */
#define PRIoPTR "lo" /* uintptr_t */
#define PRIu8 "u" /* uint8_t */
#define PRIu16 "u" /* uint16_t */
#define PRIu32 "lu" /* uint32_t */
#define PRIuLEAST8 "u" /* uint_least8_t */
#define PRIuLEAST16 "u" /* uint_least16_t */
#define PRIuLEAST32 "lu" /* uint_least32_t */
#define PRIuFAST8 "u" /* uint_fast8_t */
#define PRIuFAST16 "u" /* uint_fast16_t */
#define PRIuFAST32 "lu" /* uint_fast32_t */
#define PRIuMAX "lu" /* uintmax_t */
#define PRIuPTR "lu" /* uintptr_t */
#define PRIx8 "x" /* uint8_t */
#define PRIx16 "x" /* uint16_t */
#define PRIx32 "lx" /* uint32_t */
#define PRIxLEAST8 "x" /* uint_least8_t */
#define PRIxLEAST16 "x" /* uint_least16_t */
#define PRIxLEAST32 "lx" /* uint_least32_t */
#define PRIxFAST8 "x" /* uint_fast8_t */
#define PRIxFAST16 "x" /* uint_fast16_t */
#define PRIxFAST32 "lx" /* uint_fast32_t */
#define PRIxMAX "lx" /* uintmax_t */
#define PRIxPTR "lx" /* uintptr_t */
#define PRIX8 "X" /* uint8_t */
#define PRIX16 "X" /* uint16_t */
#define PRIX32 "lX" /* uint32_t */
#define PRIXLEAST8 "X" /* uint_least8_t */
#define PRIXLEAST16 "X" /* uint_least16_t */
#define PRIXLEAST32 "lX" /* uint_least32_t */
#define PRIXFAST8 "X" /* uint_fast8_t */
#define PRIXFAST16 "X" /* uint_fast16_t */
#define PRIXFAST32 "lX" /* uint_fast32_t */
#define PRIXMAX "lX" /* uintmax_t */
#define PRIXPTR "lX" /* uintptr_t */
/* fscanf macros for signed integers */
#define SCNd16 "hd" /* int16_t */
#define SCNd32 "ld" /* int32_t */
#define SCNdLEAST16 "hd" /* int_least16_t */
#define SCNdLEAST32 "ld" /* int_least32_t */
#define SCNdFAST8 "hd" /* int_fast8_t */
#define SCNdFAST16 "hd" /* int_fast16_t */
#define SCNdFAST32 "ld" /* int_fast32_t */
#define SCNdMAX "ld" /* intmax_t */
#define SCNdPTR "ld" /* intptr_t */
#define SCNi16 "hi" /* int16_t */
#define SCNi32 "li" /* int32_t */
#define SCNiLEAST16 "hi" /* int_least16_t */
#define SCNiLEAST32 "li" /* int_least32_t */
#define SCNiFAST8 "hi" /* int_fast8_t */
#define SCNiFAST16 "hi" /* int_fast16_t */
#define SCNiFAST32 "li" /* int_fast32_t */
#define SCNiMAX "li" /* intmax_t */
#define SCNiPTR "li" /* intptr_t */
/* fscanf macros for unsigned integers */
#define SCNo16 "ho" /* uint16_t */
#define SCNo32 "lo" /* uint32_t */
#define SCNoLEAST16 "ho" /* uint_least16_t */
#define SCNoLEAST32 "lo" /* uint_least32_t */
#define SCNoFAST8 "ho" /* uint_fast8_t */
#define SCNoFAST16 "ho" /* uint_fast16_t */
#define SCNoFAST32 "lo" /* uint_fast32_t */
#define SCNoMAX "lo" /* uintmax_t */
#define SCNoPTR "lo" /* uintptr_t */
#define SCNu16 "hu" /* uint16_t */
#define SCNu32 "lu" /* uint32_t */
#define SCNuLEAST16 "hu" /* uint_least16_t */
#define SCNuLEAST32 "lu" /* uint_least32_t */
#define SCNuFAST8 "hu" /* uint_fast8_t */
#define SCNuFAST16 "hu" /* uint_fast16_t */
#define SCNuFAST32 "lu" /* uint_fast32_t */
#define SCNuMAX "lu" /* uintmax_t */
#define SCNuPTR "lu" /* uintptr_t */
#define SCNx16 "hx" /* uint16_t */
#define SCNx32 "lx" /* uint32_t */
#define SCNxLEAST16 "hx" /* uint_least16_t */
#define SCNxLEAST32 "lx" /* uint_least32_t */
#define SCNxFAST8 "hx" /* uint_fast8_t */
#define SCNxFAST16 "hx" /* uint_fast16_t */
#define SCNxFAST32 "lx" /* uint_fast32_t */
#define SCNxMAX "lx" /* uintmax_t */
#define SCNxPTR "lx" /* uintptr_t */
/*
* The C99 and C11 standards require the following functions and the
* type imaxdiv_t to be declared here, but they are not currently supported.
*
* intmax_t imaxabs(intmax_t j);
* imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
* intmax_t strtoimax(const char * restrict nptr,
* char ** restrict endptr, int base);
* uintmax_t strtoumax(const char * restrict nptr,
* char ** restrict endptr, int base);
* intmax_t wcstoimax(const wchar_t * restrict nptr,
* wchar_t ** restrict endptr, int base);
* uintmax_t wcstoumax(const wchar_t * restrict nptr,
* wchar_t ** restrict endptr, int base);
*/
#endif

22
ORCACDefs/iso646.h Normal file
View File

@ -0,0 +1,22 @@
/****************************************************************
*
* iso646.h - alternative operator spellings
*
****************************************************************/
#ifndef __iso646__
#define __iso646__
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
#endif

141
ORCACDefs/stdint.h Normal file
View File

@ -0,0 +1,141 @@
/****************************************************************
*
* stdint.h - integer types
*
* September 2017
* Stephen Heumann
*
****************************************************************/
/*
* Note: This header mostly complies with the C99 and C11 standards,
* except that 64-bit types are not provided because ORCA/C does not
* support them. See comments below for further details.
*/
#ifndef __stdint__
#define __stdint__
/* Exact-width integer types */
typedef signed char int8_t;
typedef short int16_t;
typedef long int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
/* Minimum-width integer types */
typedef signed char int_least8_t;
typedef short int_least16_t;
typedef long int_least32_t;
typedef unsigned char uint_least8_t;
typedef unsigned short uint_least16_t;
typedef unsigned long uint_least32_t;
/* Fastest minimum-width integer types */
typedef short int_fast8_t; /* Note: 16-bit type */
typedef short int_fast16_t;
typedef long int_fast32_t;
typedef unsigned short uint_fast8_t; /* Note: 16-bit type */
typedef unsigned short uint_fast16_t;
typedef unsigned long uint_fast32_t;
/* Integer types capable of holding object pointers */
typedef long intptr_t;
typedef unsigned long uintptr_t;
/* Greatest-width integer types */
/*
* Note: In C99 and C11, these are required to be at least 64 bits.
* Since ORCA/C does not currently support 64-bit integer types,
* they are currently defined as 32-bit types instead.
*/
typedef long intmax_t;
typedef unsigned long uintmax_t;
/* Limits of exact-width integer types */
#define INT8_MIN (-128)
#define INT16_MIN (-32767-1)
#define INT32_MIN (-2147483647-1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define UINT8_MAX 255
#define UINT16_MAX 65535u
#define UINT32_MAX 4294967295u
/* Limits of minimum-width integer types */
#define INT_LEAST8_MIN (-128)
#define INT_LEAST16_MIN (-32767-1)
#define INT_LEAST32_MIN (-2147483647-1)
#define INT_LEAST8_MAX 127
#define INT_LEAST16_MAX 32767
#define INT_LEAST32_MAX 2147483647
#define UINT_LEAST8_MAX 255
#define UINT_LEAST16_MAX 65535u
#define UINT_LEAST32_MAX 4294967295u
/* Limits of fastest minimum-width integer types */
#define INT_FAST8_MIN (-32767-1)
#define INT_FAST16_MIN (-32767-1)
#define INT_FAST32_MIN (-2147483647-1)
#define INT_FAST8_MAX 32767
#define INT_FAST16_MAX 32767
#define INT_FAST32_MAX 2147483647
#define UINT_FAST8_MAX 65535u
#define UINT_FAST16_MAX 65535u
#define UINT_FAST32_MAX 4294967295u
/* Limits of integer types capable of holding object pointers */
#define INTPTR_MIN (-2147483647-1)
#define INTPTR_MAX 2147483647
#define UINTPTR_MAX 4294967295u
/* Limits of greatest-width integer types */
/* Note: These limits are smaller than C99 and C11 require. */
#define INTMAX_MIN (-2147483647-1)
#define INTMAX_MAX 2147483647
#define UINTMAX_MAX 4294967295u
/* Limits of other integer types */
#define PTRDIFF_MIN (-2147483647-1)
#define PTRDIFF_MAX 2147483647
#define SIG_ATOMIC_MIN (-32767-1)
#define SIG_ATOMIC_MAX 32767
#define SIZE_MAX 4294967295u
#ifndef WCHAR_MIN
#define WCHAR_MIN 0u
#endif
#ifndef WCHAR_MAX
#define WCHAR_MAX 65535u
#endif
/* WINT_MIN and WINT_MAX are not defined because wint_t is not defined. */
/* Macros for minimum-width integer constants */
#define INT8_C(val) (val)
#define INT16_C(val) (val)
#define INT32_C(val) (val ## L)
#define UINT8_C(val) (val)
#define UINT16_C(val) (val ## U)
#define UINT32_C(val) (val ## UL)
/* Macros for greatest-width integer constants */
/* Note: These use 32-bit types, consistent with intmax_t and uintmax_t. */
#define INTMAX_C(val) (val ## L)
#define UINTMAX_C(val) (val ## UL)
#endif