Skip to content

Commit 1806e53

Browse files
One more
1 parent 8667f8b commit 1806e53

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

middleware/include/bitstream.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// clang-format off
12
#ifndef BITSTREAM_H
23
#define BITSTREAM_H
34

@@ -30,29 +31,32 @@ void bitstream_init(bitstream_t *bitstream, uint8_t *data, size_t bytes);
3031
* @param num_bits The length of the data in bits.
3132
* @return Returns 0 if successful, -1 if there is insufficient space in the bitstream, and 1 if overflow occurs.
3233
*/
33-
#define STATIC_ASSERT(condition, message) \
34-
do { \
35-
typedef char static_assertion_##__LINE__[(condition) ? 1 : -1]; \
36-
} while (0)
34+
#define STATIC_ASSERT(condition, message) \
35+
do { \
36+
typedef char static_assertion_##__LINE__[(condition) ? 1 : -1]; \
37+
} while(0)
3738

38-
#define bitstream_add(bitstream, value, num_bits) \
39-
(STATIC_ASSERT( \
40-
__builtin_types_compatible_p(typeof(bitstream), \
41-
bitstream_t *), \
42-
"First argument of bitstream_add() must be a pointer to bitstream_t."), \
43-
STATIC_ASSERT(__builtin_types_compatible_p(typeof(num_bits), size_t), \
44-
"Third argument of bitstream_add() must be size_t."), \
45-
_Generic((value), \
46-
uint8_t: bitstream_add_uint, \
47-
uint16_t: bitstream_add_uint, \
48-
uint32_t: bitstream_add_uint, \
49-
int8_t: bitstream_add_int, \
50-
int16_t: bitstream_add_int, \
51-
int32_t: bitstream_add_int, )(bitstream, value, num_bits))
39+
#define bitstream_add(bitstream, value, num_bits) \
40+
( \
41+
STATIC_ASSERT(__builtin_types_compatible_p(typeof(bitstream), bitstream_t*), \
42+
"First argument of bitstream_add() must be a pointer to bitstream_t."), \
43+
STATIC_ASSERT(__builtin_types_compatible_p(typeof(num_bits), size_t), \
44+
"Third argument of bitstream_add() must be size_t."), \
45+
_Generic((value), \
46+
uint8_t: bitstream_add_uint, \
47+
uint16_t: bitstream_add_uint, \
48+
uint32_t: bitstream_add_uint, \
49+
int8_t: bitstream_add_int, \
50+
int16_t: bitstream_add_int, \
51+
int32_t: bitstream_add_int, \
52+
default: bitstream_add_unsupported_type \
53+
)(bitstream, value, num_bits) \
54+
)
5255

5356
/* Internal functions (not meant to be called directly). */
5457
/* Used by the bitstream_add() macro depending on the input data type. */
5558
int bitstream_add_uint(bitstream_t *bitstream, uint32_t value, size_t num_bits);
5659
int bitstream_add_int(bitstream_t *bitstream, int32_t value, size_t num_bits);
5760

58-
#endif // BITSTREAM_H
61+
#endif // BITSTREAM_H
62+
// clang-format on

0 commit comments

Comments
 (0)