From 5a6ef8366caf2edacce687902e9bed60d4ecf912 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Fri, 6 Nov 2015 12:40:57 +0100 Subject: [PATCH] gmio_core: add typedef for 64b integers --- CMakeLists.txt | 22 ++++++++++++++++++++++ src/gmio_core/config.h.cmake | 5 +++++ src/gmio_core/global.h | 27 ++++++++++++++++++--------- tests/test_core_platform.c | 5 +++++ 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7efa96a..d9e29c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,7 @@ endif() # Find bit size of the target architecture math(EXPR GMIO_TARGET_ARCH_BIT_SIZE "8 * ${CMAKE_SIZEOF_VOID_P}") +message(STATUS "GMIO_TARGET_ARCH_BIT_SIZE = ${GMIO_TARGET_ARCH_BIT_SIZE}") # Test if host's architecture is big-endian include(TestBigEndian) @@ -82,6 +83,27 @@ check_include_files(stdint.h GMIO_HAVE_STDINT_H) # Check non-ANSI available features if(NOT GMIO_BUILD_STRICT_C90) + # Check availability of a 64b integer type + if(GMIO_HAVE_STDINT_H) + set(CMAKE_REQUIRED_INCLUDES stdint.h) + endif() + check_type_size("int64_t" GMIO_SIZEOF_INT64_T) + if(NOT HAVE_GMIO_SIZEOF_INT64_T) + check_type_size("__int64" GMIO_SIZEOF_MSVC_INT64) + if(NOT HAVE_GMIO_SIZEOF_MSVC_INT64) + check_type_size("long long" GMIO_SIZEOF_LONG_LONG) + endif() + endif() + set(CMAKE_REQUIRED_INCLUDES) + + if(HAVE_GMIO_SIZEOF_INT64_T) + set(GMIO_HAVE_INT64_T ${HAVE_GMIO_SIZEOF_INT64_T}) + elseif(HAVE_GMIO_SIZEOF_MSVC_INT64) + set(GMIO_HAVE_MSVC_INT64 ${HAVE_GMIO_SIZEOF_MSVC_INT64}) + elseif(HAVE_GMIO_SIZEOF_LONG_LONG) + set(GMIO_HAVE_LONG_LONG ${HAVE_GMIO_SIZEOF_LONG_LONG}) + endif() + # Check C99 features check_function_exists(strtof GMIO_HAVE_STRTOF_FUNC) diff --git a/src/gmio_core/config.h.cmake b/src/gmio_core/config.h.cmake index 0858e74..266fd36 100644 --- a/src/gmio_core/config.h.cmake +++ b/src/gmio_core/config.h.cmake @@ -18,6 +18,11 @@ #ifndef GMIO_CONFIG_H_CMAKE #define GMIO_CONFIG_H_CMAKE +/* 64b integer type */ +#cmakedefine GMIO_HAVE_INT64_T +#cmakedefine GMIO_HAVE_MSVC_INT64 +#cmakedefine GMIO_HAVE_LONG_LONG + /* C99 */ #ifndef GMIO_HAVE_STDINT_H #cmakedefine GMIO_HAVE_STDINT_H diff --git a/src/gmio_core/global.h b/src/gmio_core/global.h index 7bbaac9..2040975 100644 --- a/src/gmio_core/global.h +++ b/src/gmio_core/global.h @@ -75,22 +75,31 @@ typedef char int8_t; typedef unsigned char uint8_t; +/* TODO: short is not necessarily 16b on all archs */ typedef short int16_t; typedef unsigned short uint16_t; +/* TODO: int is not necessarily 32b on all archs */ typedef int int32_t; typedef unsigned int uint32_t; - -/*# ifdef _MSC_VER -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -# else -typedef long long int64_t; -typedef unsigned long long uint64_t; -# endif*/ /* _MSC_VER */ - #endif /* GMIO_USE_STDINT_H */ +#ifndef GMIO_HAVE_INT64_T +# if defined(GMIO_HAVE_MSVC_INT64) +typedef __int64_t int64_t; +typedef unsigned __int64_t uint64_t; +# elif defined(GMIO_HAVE_LONG_LONG) +typedef long long int64_t; +typedef unsigned long long uint64_t; +# endif +#endif /* !GMIO_HAVE_INT64_T */ + +#if defined(GMIO_HAVE_INT64_T) \ + || defined(GMIO_HAVE_MSVC_INT64) \ + || defined(GMIO_HAVE_LONG_LONG) +# define GMIO_HAVE_INT64_TYPE +#endif + #ifdef GMIO_HAVE_STDBOOL_H # include diff --git a/tests/test_core_platform.c b/tests/test_core_platform.c index 8d825a7..ffade55 100644 --- a/tests/test_core_platform.c +++ b/tests/test_core_platform.c @@ -55,6 +55,11 @@ const char* test_platform__global_h() UTEST_ASSERT(sizeof(int32_t) == 4); UTEST_ASSERT(sizeof(uint32_t) == 4); +#ifdef GMIO_HAVE_INT64_TYPE + UTEST_ASSERT(sizeof(int64_t) == 8); + UTEST_ASSERT(sizeof(uint64_t) == 8); +#endif + UTEST_ASSERT(sizeof(gmio_float32_t) == 4); UTEST_ASSERT(sizeof(gmio_float64_t) == 8);