Skip to content

Commit

Permalink
Data: Switch to using C11 style static assert.
Browse files Browse the repository at this point in the history
  • Loading branch information
tlsa committed Feb 27, 2021
1 parent ab3198b commit a05e7db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ static inline void cyaml_data_write_pointer(
{
/* Refuse to build on platforms where sizeof pointer would
* lead to \ref CYAML_ERR_INVALID_DATA_SIZE. */
cyaml_static_assert(sizeof(char *) > 0);
cyaml_static_assert(sizeof(char *) <= sizeof(uint64_t));
static_assert(sizeof(char *) > 0, "Incompatible pointer size.");
static_assert(sizeof(char *) <= sizeof(uint64_t),
"Incompatible pointer size.");

CYAML_UNUSED(cyaml_data_write((uint64_t)ptr, sizeof(ptr), data_target));

Expand Down Expand Up @@ -115,8 +116,9 @@ static inline uint8_t * cyaml_data_read_pointer(

/* Refuse to build on platforms where sizeof pointer would
* lead to \ref CYAML_ERR_INVALID_DATA_SIZE. */
cyaml_static_assert(sizeof(char *) > 0);
cyaml_static_assert(sizeof(char *) <= sizeof(uint64_t));
static_assert(sizeof(char *) > 0, "Incompatible pointer size.");
static_assert(sizeof(char *) <= sizeof(uint64_t),
"Incompatible pointer size.");

return (void *)cyaml_data_read(sizeof(char *), data, &err);
}
Expand Down
8 changes: 0 additions & 8 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
#include "cyaml/cyaml.h"
#include "utf8.h"

/** Compile time assertion macro. */
#define cyaml_static_assert(e) \
{ \
enum { \
cyaml_static_assert_check = 1 / (!!(e)) \
}; \
}

/** Macro to squash unused variable compiler warnings. */
#define CYAML_UNUSED(_x) ((void)(_x))

Expand Down

0 comments on commit a05e7db

Please sign in to comment.