gmio_core: safer int types when no <stdint.h>
This commit is contained in:
parent
47b134797a
commit
efe3e64648
@ -81,6 +81,11 @@ set(CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS}")
|
|||||||
# Some compilers (like GCC v4.9) don't disable <stdint.h> in STRICT_ANSI mode
|
# Some compilers (like GCC v4.9) don't disable <stdint.h> in STRICT_ANSI mode
|
||||||
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
check_include_files(stdint.h GMIO_HAVE_STDINT_H)
|
||||||
|
|
||||||
|
# Find size of short, int and long types
|
||||||
|
check_type_size("short" GMIO_SIZEOF_SHORT)
|
||||||
|
check_type_size("int" GMIO_SIZEOF_INT)
|
||||||
|
check_type_size("long" GMIO_SIZEOF_LONG)
|
||||||
|
|
||||||
# Check non-ANSI available features
|
# Check non-ANSI available features
|
||||||
if(NOT GMIO_BUILD_STRICT_C90)
|
if(NOT GMIO_BUILD_STRICT_C90)
|
||||||
# Check availability of a 64b integer type
|
# Check availability of a 64b integer type
|
||||||
|
@ -18,6 +18,11 @@
|
|||||||
#ifndef GMIO_CONFIG_H_CMAKE
|
#ifndef GMIO_CONFIG_H_CMAKE
|
||||||
#define GMIO_CONFIG_H_CMAKE
|
#define GMIO_CONFIG_H_CMAKE
|
||||||
|
|
||||||
|
/* Size(in bytes) of integer types */
|
||||||
|
#cmakedefine GMIO_SIZEOF_SHORT @GMIO_SIZEOF_SHORT@
|
||||||
|
#cmakedefine GMIO_SIZEOF_INT @GMIO_SIZEOF_INT@
|
||||||
|
#cmakedefine GMIO_SIZEOF_LONG @GMIO_SIZEOF_LONG@
|
||||||
|
|
||||||
/* 64b integer type */
|
/* 64b integer type */
|
||||||
#cmakedefine GMIO_HAVE_INT64_T
|
#cmakedefine GMIO_HAVE_INT64_T
|
||||||
#cmakedefine GMIO_HAVE_MSVC_INT64
|
#cmakedefine GMIO_HAVE_MSVC_INT64
|
||||||
|
@ -27,6 +27,13 @@
|
|||||||
#ifndef GMIO_GLOBAL_H
|
#ifndef GMIO_GLOBAL_H
|
||||||
#define GMIO_GLOBAL_H
|
#define GMIO_GLOBAL_H
|
||||||
|
|
||||||
|
/* "config.h" is generated by cmake, it should reside in the out-of-source
|
||||||
|
* build dir.
|
||||||
|
* In CMakeFiles.txt, the directory where resides "config.h" is added to the
|
||||||
|
* include path list
|
||||||
|
*/
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
/* GMIO_OS_WIN */
|
/* GMIO_OS_WIN */
|
||||||
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) \
|
#if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) \
|
||||||
|| defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
|
|| defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
|
||||||
@ -69,13 +76,6 @@
|
|||||||
# define GMIO_LIB_EXPORT
|
# define GMIO_LIB_EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* "config.h" is generated by cmake, it should reside in the out-of-source
|
|
||||||
* build dir.
|
|
||||||
* In CMakeFiles.txt, the directory where resides "config.h" is added to the
|
|
||||||
* include path list
|
|
||||||
*/
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
/* Typedefs for specific width integers */
|
/* Typedefs for specific width integers */
|
||||||
#ifdef GMIO_HAVE_STDINT_H
|
#ifdef GMIO_HAVE_STDINT_H
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
@ -83,17 +83,26 @@
|
|||||||
typedef char int8_t;
|
typedef char int8_t;
|
||||||
typedef unsigned char uint8_t;
|
typedef unsigned char uint8_t;
|
||||||
|
|
||||||
/* TODO: short is not necessarily 16b on all archs */
|
# if GMIO_SIZEOF_SHORT == 2
|
||||||
typedef short int16_t;
|
typedef short int16_t;
|
||||||
typedef unsigned short uint16_t;
|
typedef unsigned short uint16_t;
|
||||||
|
# else
|
||||||
/* TODO: int is not necessarily 32b on all archs */
|
# error Not supported: sizeof(short) != 2
|
||||||
typedef int int32_t;
|
|
||||||
typedef unsigned int uint32_t;
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
/* int64_t */
|
# if GMIO_SIZEOF_INT == 4
|
||||||
/* uint64_t */
|
typedef int int32_t;
|
||||||
|
typedef unsigned int uint32_t;
|
||||||
|
# elif GMIO_SIZEOF_LONG == 4
|
||||||
|
typedef long int32_t;
|
||||||
|
typedef unsigned long uint32_t;
|
||||||
|
# else
|
||||||
|
# error Failed to find a 32bit integer type with 'int' and 'long'
|
||||||
|
# endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* (u)int64_t */
|
||||||
#ifndef GMIO_HAVE_INT64_T
|
#ifndef GMIO_HAVE_INT64_T
|
||||||
# if defined(GMIO_HAVE_MSVC_INT64)
|
# if defined(GMIO_HAVE_MSVC_INT64)
|
||||||
typedef __int64_t int64_t;
|
typedef __int64_t int64_t;
|
||||||
|
Loading…
Reference in New Issue
Block a user