Skip to content

Commit

Permalink
Revert "Data: Switch to using C11 style static assert."
Browse files Browse the repository at this point in the history
This reverts commit a05e7db.

Unfortunatly some versions of some platforms' C library
headers don't provide the C11 static_assert macro wrapper
for _Static_assert.

Rather than hacking around it, this reverts to using a
C89-compatible static assertion macro.

Fixes #230
  • Loading branch information
tlsa committed May 22, 2024
1 parent 66b7206 commit c24bfaf
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 c24bfaf

Please sign in to comment.