From a74886b564f74f073259cf99f90fd1be13e8053a Mon Sep 17 00:00:00 2001 From: yixy <34703796+yixy-only@users.noreply.github.com> Date: Thu, 28 Nov 2024 23:21:18 +0800 Subject: [PATCH] =?UTF-8?q?ajudst:=20stdint.h=20=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=B8=8D=E5=90=8C=E7=BC=96=E8=AF=91=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E7=A7=BB=E8=87=B3=20include/ege=20=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=20(#242)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 调整 stdint.h,以兼容不同版本的编译器 * adjust: stdint.h 移至 include/ege 目录 --- include/ege.h | 5 +- {src => include/ege}/stdint.h | 100 ++++++++++++++++++++++++++++------ src/types.h | 10 ---- 3 files changed, 86 insertions(+), 29 deletions(-) rename {src => include/ege}/stdint.h (66%) diff --git a/include/ege.h b/include/ege.h index 18e4c807..e71c8fea 100644 --- a/include/ege.h +++ b/include/ege.h @@ -72,6 +72,7 @@ #endif #endif +#include "ege/stdint.h" #if defined(EGE_FOR_AUTO_CODE_COMPLETETION_ONLY) #include @@ -125,12 +126,12 @@ #ifndef EGE_DEPRECATE # ifdef _MSC_VER # ifdef _CRT_DEPRECATE_TEXT -# define EGE_DEPRECATE(function, msg) _CRT_DEPRECATE_TEXT("This function is deprecated. " msg " For more information, visit https://xege.org/.") +# define EGE_DEPRECATE(function, msg) _CRT_DEPRECATE_TEXT("This function is deprecated. " msg " For more information, visit https://xege.org .") # else # define EGE_DEPRECATE(function, msg) # endif # elif ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5))) -# define EGE_DEPRECATE(function, msg) __attribute__((deprecated(msg " For more information, visit https://xege.org/."))) +# define EGE_DEPRECATE(function, msg) __attribute__((deprecated(msg " For more information, visit https://xege.org ."))) # else # define EGE_DEPRECATE(function, msg) __attribute__((deprecated)) # endif diff --git a/src/stdint.h b/include/ege/stdint.h similarity index 66% rename from src/stdint.h rename to include/ege/stdint.h index 8b970b66..13dceee6 100644 --- a/src/stdint.h +++ b/include/ege/stdint.h @@ -18,10 +18,68 @@ #ifndef _STDINT_H #define _STDINT_H + +#if defined(_MSC_VER) && (_MSC_VER > 1000) +#pragma once +#endif + +#ifndef _STDINT_HEADER_NOT_SUPPORT +#if defined(_MSC_VER) && (_MSC_VER < 1600) +#define _STDINT_HEADER_NOT_SUPPORT +#elif defined(__GNUC__) && ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 5))) +#define _STDINT_HEADER_NOT_SUPPORT +#else + /* Other compilers always assume support for . */ +#endif +#endif + +/* If the compiler provides the stdint.h header, fall back to the compiler's stdint.h, + * which might have additional definitions. + */ +#if !defined(_STDINT_HEADER_NOT_SUPPORT) + +/* Remove the include guard before including the header file to ensure it is included. */ +#undef _STDINT_H +#include +#ifndef _STDINT_H +#define _STDINT_H +#endif + +#else + +/* Avoid duplication with definitions in other stdint.h header files */ +#if !definded(_STDINT) && !defined(_GCC_STDINT_H) +#if defined(_MSC_VER) +#define _STDINT +#elif defined(__GNUC__) +#define _GCC_STDINT_H +#endif + #define __need_wint_t #define __need_wchar_t #include +#ifndef _LONGLONG +#if defined(_MSC_VER) && (_MSC_VER < 1800) +#define _LONGLONG __int64 +#else +#define _LONGLONG long long +#endif +#endif + +#ifndef __GNUC_EXTENSION__ +#if defined(__GNUC__) +#define __GNUC_EXTENSION__ __extension__ +#else +#define __GNUC_EXTENSION__ +#endif +#endif + +#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wlong-long" +#endif + /* 7.18.1.1 Exact-width integer types */ typedef signed char int8_t; typedef unsigned char uint8_t; @@ -29,8 +87,8 @@ typedef short int16_t; typedef unsigned short uint16_t; typedef int int32_t; typedef unsigned uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; +__GNUC_EXTENSION__ typedef _LONGLONG int64_t; +__GNUC_EXTENSION__ typedef unsigned _LONGLONG uint64_t; /* 7.18.1.2 Minimum-width integer types */ typedef signed char int_least8_t; @@ -39,8 +97,8 @@ typedef short int_least16_t; typedef unsigned short uint_least16_t; typedef int int_least32_t; typedef unsigned uint_least32_t; -typedef long long int_least64_t; -typedef unsigned long long uint_least64_t; +__GNUC_EXTENSION__ typedef _LONGLONG int_least64_t; +__GNUC_EXTENSION__ typedef unsigned _LONGLONG uint_least64_t; /* 7.18.1.3 Fastest minimum-width integer types * Not actually guaranteed to be fastest for all purposes @@ -52,15 +110,16 @@ typedef short int_fast16_t; typedef unsigned short uint_fast16_t; typedef int int_fast32_t; typedef unsigned int uint_fast32_t; -typedef long long int_fast64_t; -typedef unsigned long long uint_fast64_t; +__GNUC_EXTENSION__ typedef _LONGLONG int_fast64_t; +__GNUC_EXTENSION__ typedef unsigned _LONGLONG uint_fast64_t; /* 7.18.1.4 Integer types capable of holding object pointers */ - #ifndef _INTPTR_T_DEFINED #define _INTPTR_T_DEFINED -#ifdef _WIN64 -typedef __int64 intptr_t; +#if defined(__INTPTR_TYPE__) +__GNUC_EXTENSION__ typedef __INTPTR_TYPE__ intptr_t; +#elif defined(_WIN64) || defined(__x86_64__) || (defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)) +__GNUC_EXTENSION__ typedef _LONGLONG intptr_t; #else typedef int intptr_t; #endif @@ -68,16 +127,18 @@ typedef int intptr_t; #ifndef _UINTPTR_T_DEFINED #define _UINTPTR_T_DEFINED -#ifdef _WIN64 -typedef unsigned __int64 uintptr_t; +#if defined(__UINTPTR_TYPE__) +__GNUC_EXTENSION__ typedef __UINTPTR_TYPE__ uintptr_t; +#elif defined(_WIN64) || defined(__x86_64__) || (defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)) +__GNUC_EXTENSION__ typedef unsigned _LONGLONG uintptr_t; #else typedef unsigned int uintptr_t; #endif #endif /* 7.18.1.5 Greatest-width integer types */ -typedef long long intmax_t; -typedef unsigned long long uintmax_t; +__GNUC_EXTENSION__ typedef _LONGLONG intmax_t; +__GNUC_EXTENSION__ typedef unsigned _LONGLONG uintmax_t; /* 7.18.2 Limits of specified-width integer types */ #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) @@ -132,7 +193,7 @@ typedef unsigned long long uintmax_t; /* 7.18.2.4 Limits of integer types capable of holding object pointers */ -#ifdef _WIN64 +#if defined(_WIN64) || defined(__x86_64__) || (defined(__SIZEOF_POINTER__) && (__SIZEOF_POINTER__ == 8)) #define INTPTR_MIN INT64_MIN #define INTPTR_MAX INT64_MAX #define UINTPTR_MAX UINT64_MAX @@ -142,7 +203,7 @@ typedef unsigned long long uintmax_t; #define UINTPTR_MAX UINT32_MAX #endif -/* 7.18.2.5 Limits of greatest-width integer types */ + /* 7.18.2.5 Limits of greatest-width integer types */ #define INTMAX_MIN INT64_MIN #define INTMAX_MAX INT64_MAX #define UINTMAX_MAX UINT64_MAX @@ -169,7 +230,7 @@ typedef unsigned long long uintmax_t; #endif /* !defined ( __cplusplus) || defined __STDC_LIMIT_MACROS */ -/* 7.18.4 Macros for integer constants */ + /* 7.18.4 Macros for integer constants */ #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) /* 7.18.4.1 Macros for minimum-width integer constants @@ -198,7 +259,12 @@ typedef unsigned long long uintmax_t; /* 7.18.4.2 Macros for greatest-width integer constants */ #define INTMAX_C(val) INT64_C(val) #define UINTMAX_C(val) UINT64_C(val) - #endif /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */ +#if defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))) +#pragma GCC diagnostic pop #endif + +#endif /* !definded(_STDINT) && !defined(_GCC_STDINT_H) */ +#endif /* !defined(_STDINT_HEADER_NOT_SUPPORT) */ +#endif /* _STDINT_H */ diff --git a/src/types.h b/src/types.h index f7d9b6dc..c3ede008 100644 --- a/src/types.h +++ b/src/types.h @@ -1,15 +1,5 @@ #pragma once -// MSVC 从 10.0(VS2010)开始有 stdint.h -// GCC 从 4.5 开始有 stdint.h -#if _MSC_VER >= 1600 || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) -#include -#elif !defined(_MSC_VER) || _MSC_VER > 1300 -#include "stdint.h" -#else -typedef unsigned uint32_t; -#endif - #include #include