Skip to content

Commit 0d54cf5

Browse files
authored
Merge pull request #6645 from Yay295/int_def
Better C integer definitions
2 parents 6c464b8 + 36487fe commit 0d54cf5

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

src/libImaging/ImPlatform.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#endif
2626
#endif
2727

28-
#if defined(_WIN32) || defined(__CYGWIN__)
28+
#if defined(_WIN32) || defined(__CYGWIN__) /* WIN */
2929

3030
#define WIN32_LEAN_AND_MEAN
3131
#include <Windows.h>
@@ -37,15 +37,33 @@
3737
#undef WIN32
3838
#endif
3939

40-
#else
40+
#else /* not WIN */
4141
/* For System that are not Windows, we'll need to define these. */
42+
/* We have to define them instead of using typedef because the JPEG lib also
43+
defines their own types with the same names, so we need to be able to undef
44+
ours before including the JPEG code. */
45+
46+
#if __STDC_VERSION__ >= 199901L /* C99+ */
47+
48+
#include <stdint.h>
49+
50+
#define INT8 int8_t
51+
#define UINT8 uint8_t
52+
#define INT16 int16_t
53+
#define UINT16 uint16_t
54+
#define INT32 int32_t
55+
#define UINT32 uint32_t
56+
57+
#else /* < C99 */
58+
59+
#define INT8 signed char
4260

4361
#if SIZEOF_SHORT == 2
4462
#define INT16 short
4563
#elif SIZEOF_INT == 2
4664
#define INT16 int
4765
#else
48-
#define INT16 short /* most things works just fine anyway... */
66+
#error Cannot find required 16-bit integer type
4967
#endif
5068

5169
#if SIZEOF_SHORT == 4
@@ -58,13 +76,13 @@
5876
#error Cannot find required 32-bit integer type
5977
#endif
6078

61-
#define INT8 signed char
6279
#define UINT8 unsigned char
63-
6480
#define UINT16 unsigned INT16
6581
#define UINT32 unsigned INT32
6682

67-
#endif
83+
#endif /* < C99 */
84+
85+
#endif /* not WIN */
6886

6987
/* assume IEEE; tweak if necessary (patches are welcome) */
7088
#define FLOAT16 UINT16

0 commit comments

Comments
 (0)