Skip to content

Commit 3e23929

Browse files
rzrthiagomacieira
authored andcommitted
Support C99 standards (enums, assert)
Fix various errors when -Werror=pedantic flag is enabled: Cast enum values to int to prevent errors like: deps/tinycbor/src/cborconstants_p.h:47:31:\ error: ISO C restricts enumerator values to range of ‘int’\ [-Werror=pedantic] MajorTypeMask = ~0U << MajorTypeShift, "error: ISO C99 does not support" ‘Static_assert’ This effort is needed for RIOT port of iotivity-contrained Bug-RIOT: RIOT-OS/RIOT#6241 Signed-off-by: Philippe Coval <[email protected]> Signed-off-by: Thiago Macieira <[email protected]>
1 parent 8ba8e20 commit 3e23929

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/cbor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ typedef enum CborError {
151151
CborErrorJsonObjectKeyNotString,
152152
CborErrorJsonNotImplemented,
153153

154-
CborErrorOutOfMemory = ~0U / 2 + 1,
155-
CborErrorInternalError = ~0U
154+
CborErrorOutOfMemory = (int) (~0U / 2 + 1),
155+
CborErrorInternalError = (int) ~0U
156156
} CborError;
157157

158158
CBOR_API const char *cbor_error_string(CborError error);

src/cborconstants_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum {
4444
IndefiniteLength = 31U,
4545

4646
MajorTypeShift = SmallValueBitLength,
47-
MajorTypeMask = ~0U << MajorTypeShift,
47+
MajorTypeMask = (int) (~0U << MajorTypeShift),
4848

4949
BreakByte = (unsigned)Break | (SimpleTypesType << MajorTypeShift)
5050
};

src/compilersupport_p.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
#if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L || __cpp_static_assert >= 200410
5151
# define cbor_static_assert(x) static_assert(x, #x)
52-
#elif !defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406)
52+
#elif !defined(__cplusplus) && defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406) && (__STDC_VERSION__ > 199901L)
5353
# define cbor_static_assert(x) _Static_assert(x, #x)
5454
#else
5555
# define cbor_static_assert(x) ((void)sizeof(char[2*!!(x) - 1]))

0 commit comments

Comments
 (0)