Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better C integer definitions #6645

Merged
merged 10 commits into from Jun 24, 2023
41 changes: 34 additions & 7 deletions src/libImaging/ImPlatform.h
Expand Up @@ -25,7 +25,7 @@
#endif
#endif

#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
Expand All @@ -37,15 +37,37 @@
#undef WIN32
#endif

#else
#else /* WIN */
Yay295 marked this conversation as resolved.
Show resolved Hide resolved
/* For System that are not Windows, we'll need to define these. */
/* We have to define them instead of using typedef because the JPEG lib also
defines their own types with the same names, so we need to be able to undef
ours before including the JPEG code. */

#if __STDC_VERSION__ >= 199901L /* C99+ */

#include <stdint.h>

#define INT8 int8_t
#define UINT8 uint8_t
#define INT16 int16_t
#define UINT16 uint16_t
#define INT32 int32_t
#define UINT32 uint32_t
#ifdef INT64_MAX
#define INT64 int64_t
#define UINT64 uint64_t
#endif

#else /* C99+ */
Yay295 marked this conversation as resolved.
Show resolved Hide resolved

#define INT8 signed char

#if SIZEOF_SHORT == 2
#define INT16 short
#elif SIZEOF_INT == 2
#define INT16 int
#else
#define INT16 short /* most things works just fine anyway... */
#error Cannot find required 16-bit integer type
#endif

#if SIZEOF_SHORT == 4
Expand All @@ -61,17 +83,22 @@
#if SIZEOF_LONG == 8
#define INT64 long
#elif SIZEOF_LONG_LONG == 8
#define INT64 long
#define INT64 long long
#else
#warning Cannot find required 64-bit integer type
Yay295 marked this conversation as resolved.
Show resolved Hide resolved
#endif

#define INT8 signed char
#define UINT8 unsigned char

#define UINT16 unsigned INT16
#define UINT32 unsigned INT32

#ifdef INT64
#define UINT64 unsigned INT64
Yay295 marked this conversation as resolved.
Show resolved Hide resolved
#endif

#endif /* C99+ */

#endif /* WIN */
Yay295 marked this conversation as resolved.
Show resolved Hide resolved

/* assume IEEE; tweak if necessary (patches are welcome) */
#define FLOAT16 UINT16
#define FLOAT32 float
Expand Down