From e1f6b4a26399b0e7849fd646fe5ee690231b32d4 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Thu, 8 Mar 2018 10:00:33 +0800 Subject: [PATCH] scanner: More compatible flex integer type definitions. Visual C++ 2010 does not define __STDC_VERSION__, and (before Visual C++ 2013) has and not . ANSI/ISO C only requires at least 16 bits for int type (not 32 bits as required by POSIX since SUSv2), so check the bit length before the typedef. Signed-off-by: Kang-Che Sung --- src/flexint_shared.h | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/flexint_shared.h b/src/flexint_shared.h index 569f073..5532813 100644 --- a/src/flexint_shared.h +++ b/src/flexint_shared.h @@ -6,6 +6,17 @@ * and not the latter. */ #include +# define YYFLEX_USE_STDINT +#else +# if defined(_MSC_VER) && _MSC_VER >= 1600 +/* Visual C++ 2010 does not define __STDC_VERSION__ and has but not + * . + */ +#include +# define YYFLEX_USE_STDINT +# endif +#endif +#ifdef YYFLEX_USE_STDINT typedef int8_t flex_int8_t; typedef uint8_t flex_uint8_t; typedef int16_t flex_int16_t; @@ -13,10 +24,23 @@ typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; #else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; typedef unsigned char flex_uint8_t; +typedef short int flex_int16_t; typedef unsigned short int flex_uint16_t; +# ifdef __STDC__ +typedef signed char flex_int8_t; +/* ISO C only requires at least 16 bits for int. */ +#include +# if UINT_MAX >= 4294967295 +# define YYFLEX_INT32_DEFINED +typedef int flex_int32_t; typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ +# endif +# else +typedef char flex_int8_t; +# endif +# ifndef YYFLEX_INT32_DEFINED +typedef long int flex_int32_t; +typedef unsigned long int flex_uint32_t; +# endif +#endif -- 2.40.0