Skip to content

Commit 86c8186

Browse files
Properly fix support for stdint.h on Arduino
There are at least two fixes in the codebase already due to macros that should have come from stdint.h not being defined. I was blaming the libc, as stdint.h is a C99 header and C99 requires those macros. Turns out that the Arduino toolchain compiles everything as C++ and officially C++98 does not have stdint.h, so "anything goes". The Arduino docs recommend #define'ing __STDC_LIMIT_MACROS to get those macros. Signed-off-by: Thiago Macieira <[email protected]>
1 parent 31c7f81 commit 86c8186

File tree

7 files changed

+28
-3
lines changed

7 files changed

+28
-3
lines changed

src/cborencoder.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#define _BSD_SOURCE 1
2626
#define _DEFAULT_SOURCE 1
27+
#ifndef __STDC_LIMIT_MACROS
28+
# define __STDC_LIMIT_MACROS 1
29+
#endif
30+
2731
#include "cbor.h"
2832
#include "cborconstants_p.h"
2933
#include "compilersupport_p.h"

src/cborencoder_close_container_checked.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#define _BSD_SOURCE 1
2626
#define _DEFAULT_SOURCE 1
27+
#ifndef __STDC_LIMIT_MACROS
28+
# define __STDC_LIMIT_MACROS 1
29+
#endif
30+
2731
#include "cbor.h"
2832
#include "cborconstants_p.h"
2933
#include "compilersupport_p.h"

src/cborparser.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#define _BSD_SOURCE 1
2626
#define _DEFAULT_SOURCE 1
27+
#ifndef __STDC_LIMIT_MACROS
28+
# define __STDC_LIMIT_MACROS 1
29+
#endif
30+
2731
#include "cbor.h"
2832
#include "cborconstants_p.h"
2933
#include "compilersupport_p.h"

src/cborparser_dup_string.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#define _BSD_SOURCE 1
2626
#define _DEFAULT_SOURCE 1
27+
#ifndef __STDC_LIMIT_MACROS
28+
# define __STDC_LIMIT_MACROS 1
29+
#endif
30+
2731
#include "cbor.h"
2832
#include <stdlib.h>
2933

src/cborpretty.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#define _BSD_SOURCE 1
2626
#define _DEFAULT_SOURCE 1
27+
#ifndef __STDC_LIMIT_MACROS
28+
# define __STDC_LIMIT_MACROS 1
29+
#endif
30+
2731
#include "cbor.h"
2832
#include "compilersupport_p.h"
2933
#include "math_support_p.h"

src/cbortojson.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#define _DEFAULT_SOURCE 1
2727
#define _GNU_SOURCE 1
2828
#define _POSIX_C_SOURCE 200809L
29+
#ifndef __STDC_LIMIT_MACROS
30+
# define __STDC_LIMIT_MACROS 1
31+
#endif
32+
2933
#include "cbor.h"
3034
#include "cborjson.h"
3135
#include "compilersupport_p.h"

src/compilersupport_p.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@
6464
#define STRINGIFY(x) STRINGIFY2(x)
6565
#define STRINGIFY2(x) #x
6666

67-
#ifndef UINT32_MAX
68-
/* C99 requires it in stdint.h, but some systems lack it */
69-
# define UINT32_MAX (0xffffffffU)
67+
#if !defined(UINT32_MAX) || !defined(INT64_MAX)
68+
/* C89? We can define UINT32_MAX portably, but not INT64_MAX */
69+
# error "Your system has stdint.h but that doesn't define UINT32_MAX or INT64_MAX"
7070
#endif
71+
7172
#ifndef DBL_DECIMAL_DIG
7273
/* DBL_DECIMAL_DIG is C11 */
7374
# define DBL_DECIMAL_DIG 17

0 commit comments

Comments
 (0)