Skip to content

Commit

Permalink
Merge pull request #2 from rqou/master
Browse files Browse the repository at this point in the history
Use C99 header stdint.h to determine platform-dependent types and macros
  • Loading branch information
sterin authored Mar 30, 2018
2 parents d879336 + 8d472cd commit 4a39f32
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/misc/util/abc_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,58 @@ ABC_NAMESPACE_HEADER_START
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////

#ifdef ABC_USE_STDINT_H
// If there is stdint.h, assume this is a reasonably-modern platform that
// would also have stddef.h and limits.h
#include <limits.h>
#include <stddef.h>
#include <stdint.h>

#if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF
#define SIZEOF_VOID_P 8
#ifdef _WIN32
#define NT64
#else
#define LIN64
#endif
#elif UINTPTR_MAX == 0xFFFFFFFF
#define SIZEOF_VOID_P 4
#ifdef _WIN32
#define NT
#else
#define LIN
#endif
#else
#error unsupported platform
#endif

#if ULONG_MAX == 0xFFFFFFFFFFFFFFFF
#define SIZEOF_LONG 8
#elif ULONG_MAX == 0xFFFFFFFF
#define SIZEOF_LONG 4
#else
#error unsupported platform
#endif

#if UINT_MAX == 0xFFFFFFFFFFFFFFFF
#define SIZEOF_INT 8
#elif UINT_MAX == 0xFFFFFFFF
#define SIZEOF_INT 4
#else
#error unsupported platform
#endif

#endif

/**
* Pointer difference type; replacement for ptrdiff_t.
* This is a signed integral type that is the same size as a pointer.
* NOTE: This type may be different sizes on different platforms.
*/
#if defined(__ccdoc__)
typedef platform_dependent_type ABC_PTRDIFF_T;
#elif defined(ABC_USE_STDINT_H)
typedef ptrdiff_t ABC_PTRDIFF_T;
#elif defined(LIN64)
typedef long ABC_PTRDIFF_T;
#elif defined(NT64)
Expand All @@ -120,6 +165,8 @@ typedef int ABC_PTRDIFF_T;
*/
#if defined(__ccdoc__)
typedef platform_dependent_type ABC_PTRUINT_T;
#elif defined(ABC_USE_STDINT_H)
typedef uintptr_t ABC_PTRUINT_T;
#elif defined(LIN64)
typedef unsigned long ABC_PTRUINT_T;
#elif defined(NT64)
Expand All @@ -137,6 +184,8 @@ typedef unsigned int ABC_PTRUINT_T;
*/
#if defined(__ccdoc__)
typedef platform_dependent_type ABC_PTRINT_T;
#elif defined(ABC_USE_STDINT_H)
typedef intptr_t ABC_PTRINT_T;
#elif defined(LIN64)
typedef long ABC_PTRINT_T;
#elif defined(NT64)
Expand All @@ -152,6 +201,8 @@ typedef int ABC_PTRINT_T;
*/
#if defined(__ccdoc__)
typedef platform_dependent_type ABC_INT64_T;
#elif defined(ABC_USE_STDINT_H)
typedef int64_t ABC_INT64_T;
#elif defined(LIN64)
typedef long ABC_INT64_T;
#elif defined(NT64) || defined(LIN)
Expand All @@ -167,6 +218,8 @@ typedef signed __int64 ABC_INT64_T;
*/
#if defined(__ccdoc__)
typedef platform_dependent_type ABC_UINT64_T;
#elif defined(ABC_USE_STDINT_H)
typedef uint64_t ABC_UINT64_T;
#elif defined(LIN64)
typedef unsigned long ABC_UINT64_T;
#elif defined(NT64) || defined(LIN)
Expand Down
3 changes: 3 additions & 0 deletions src/misc/util/utilBridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#include <misc/util/abc_global.h>

#if defined(LIN) || defined(LIN64)
#include <unistd.h>
#endif
Expand Down

0 comments on commit 4a39f32

Please sign in to comment.