Skip to content

Commit

Permalink
Merge pull request #232 from tlsa/tlsa/revert-static-assert
Browse files Browse the repository at this point in the history
Revert "Data: Switch to using C11 style static assert."
  • Loading branch information
tlsa authored May 22, 2024
2 parents 66b7206 + c24bfaf commit 8199f0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ static inline void cyaml_data_write_pointer(
{
/* Refuse to build on platforms where sizeof pointer would
* lead to \ref CYAML_ERR_INVALID_DATA_SIZE. */
static_assert(sizeof(char *) > 0, "Incompatible pointer size.");
static_assert(sizeof(char *) <= sizeof(uint64_t),
"Incompatible pointer size.");
cyaml_static_assert(sizeof(char *) > 0);
cyaml_static_assert(sizeof(char *) <= sizeof(uint64_t));

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

Expand Down Expand Up @@ -116,9 +115,8 @@ 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. */
static_assert(sizeof(char *) > 0, "Incompatible pointer size.");
static_assert(sizeof(char *) <= sizeof(uint64_t),
"Incompatible pointer size.");
cyaml_static_assert(sizeof(char *) > 0);
cyaml_static_assert(sizeof(char *) <= sizeof(uint64_t));

return (void *)cyaml_data_read(sizeof(char *), data, &err);
}
Expand Down
8 changes: 8 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
#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 8199f0f

Please sign in to comment.