Skip to content

Commit

Permalink
Introduce POSIX data types and definitions
Browse files Browse the repository at this point in the history
POSIX provides portable data types for signed and unsigned integer values
of different size.

This patch maps those POSIX data types to the Tesseract specific types.
In a next step, the Tesseract data types can be eliminated by replacing
them with the POSIX data types.

Use also standard definitions for the printf format specifiers.
MS Visual Studio does not support that standard (at least not in older
versions), so local definitions are needed there.

NULL is standard, so a local definition should not be needed.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Dec 23, 2015
1 parent a361e84 commit b1c66fc
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions ccutil/host.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
#include <winbase.h> // winbase.h contains windows.h
#endif

#include <inttypes.h> // PRId32, ...
#include <stdint.h> // int32_t, ...

/********************************************************/
/* __MAC__ */
#ifdef __MAC__
Expand Down Expand Up @@ -95,25 +98,34 @@
//typedef HANDLE FD* PHANDLE;

// definitions of portable data types (numbers and characters)
typedef SIGNED char inT8;
typedef unsigned char uinT8;
typedef short inT16;
typedef unsigned short uinT16;
typedef int inT32;
typedef unsigned int uinT32;
#if (_MSC_VER >= 1200) //%%% vkr for VC 6.0
typedef INT64 inT64;
typedef UINT64 uinT64;
#else
typedef long long int inT64;
typedef unsigned long long int uinT64;
#endif //%%% vkr for VC 6.0
typedef int8_t inT8;
typedef uint8_t uinT8;
typedef int16_t inT16;
typedef uint16_t uinT16;
typedef int32_t inT32;
typedef uint32_t uinT32;
typedef int64_t inT64;
typedef uint64_t uinT64;
typedef float FLOAT32;
typedef double FLOAT64;
typedef unsigned char BOOL8;

#define INT32FORMAT "%d"
#define INT64FORMAT "%lld"
#if defined(_WIN32)

/* MinGW defines the standard PRI... macros, but MSVS doesn't. */

#if !defined(PRId32)
# define PRId32 "d"
#endif

#if !defined(PRId64)
# define PRId64 "I64d"
#endif

#endif /* _WIN32 */

#define INT32FORMAT "%" PRId32
#define INT64FORMAT "%" PRId64

#define MAX_INT8 0x7f
#define MAX_INT16 0x7fff
Expand All @@ -140,10 +152,6 @@ typedef unsigned char BOOL8;
#define FALSE 0
#endif

#ifndef NULL
#define NULL 0L
#endif

// Return true if x is within tolerance of y
template<class T> bool NearlyEqual(T x, T y, T tolerance) {
T diff = x - y;
Expand Down

0 comments on commit b1c66fc

Please sign in to comment.