From e3c2b83a0797dc56b7a537d6f8b9dbec3fa59ad7 Mon Sep 17 00:00:00 2001 From: David Declerck Date: Tue, 17 Oct 2023 17:20:14 +0200 Subject: [PATCH] Use inttypes.h and stdint.h where appropriate (fixes 920) --- ChangeLog | 4 ++++ configure.ac | 2 +- libcob/ChangeLog | 5 +++++ libcob/common.h | 26 ++++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index b34676236..ac15f8e54 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,8 @@ +2023-10-17 David Declerck + + * configure.ac: add checks to allow using stdint.h and inttypes.h + 2023-07-28 Simon Sobisch * configure.ac: check for mousemask and mmask_t diff --git a/configure.ac b/configure.ac index 477f877ce..a8e2dbc6b 100644 --- a/configure.ac +++ b/configure.ac @@ -583,7 +583,7 @@ dnl AC_CHECK_HEADERS([stdint.h whcar.h malloc.h]) AC_CHECK_HEADERS([sys/types.h signal.h stddef.h], [], [AC_MSG_ERROR([mandatory header could not be found or included])]) # optional: -AC_CHECK_HEADERS([sys/time.h locale.h fcntl.h dlfcn.h]) +AC_CHECK_HEADERS([sys/time.h locale.h fcntl.h dlfcn.h stdint.h inttypes.h]) # Checks for typedefs, structures, and compiler characteristics. diff --git a/libcob/ChangeLog b/libcob/ChangeLog index c47fc3186..cb58bbd1a 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -1,4 +1,9 @@ +2023-10-17 David Declerck + + * common.h: use stdint.h and inttypes.h when available to + define cob_s64_t, cob_u64_t and the various CB_FMT_ macros + 2023-07-28 Simon Sobisch * screenio.c, common.c: replace use of NCURSES_MOUSE_VERSION by diff --git a/libcob/common.h b/libcob/common.h index c01965eff..c4d266d03 100644 --- a/libcob/common.h +++ b/libcob/common.h @@ -45,7 +45,17 @@ typedef __mpz_struct mpz_t[1]; #define cob_sli_t long int #define cob_uli_t unsigned long int -#if defined(_WIN32) && !defined(__MINGW32__) +#ifdef HAVE_STDINT_H + +#include + +#define cob_s64_t int64_t +#define cob_u64_t uint64_t + +#define COB_S64_C(x) x ## LL +#define COB_U64_C(x) x ## ULL + +#elif defined(_WIN32) && !defined(__MINGW32__) #define cob_s64_t __int64 #define cob_u64_t unsigned __int64 @@ -63,7 +73,19 @@ typedef __mpz_struct mpz_t[1]; #endif -#if defined(_WIN32) +#ifdef HAVE_INTTYPES_H + +#include + +#define CB_FMT_LLD "%"PRId64 +#define CB_FMT_LLU "%"PRIu64 +#define CB_FMT_LLX "%"PRIx64 +#define CB_FMT_PLLD "%+*.*"PRId64 +#define CB_FMT_PLLU "%*.*"PRIu64 +#define CB_FMT_LLD_F "%"PRId64"LL" +#define CB_FMT_LLU_F "%"PRIu64"ULL" + +#elif defined(_WIN32) #define CB_FMT_LLD "%I64d" #define CB_FMT_LLU "%I64u"