Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 62de5f4

Browse files
authored
Merge pull request #5 from arkadiuszwojcik/static_assert
Implement static assert
2 parents 5281055 + e21e92f commit 62de5f4

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

include/assert.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ extern FOUNDATION_LIBC_NORETURN void foundation_libc_assert(char const * asserti
4040
#error "bad definition of FOUNDATION_LIBC_ASSERT_DEFAULT!"
4141
#endif
4242

43+
#if !defined(__cplusplus)
44+
#undef static_assert
45+
#define static_assert FOUNDATION_LIBC_STATIC_ASSERT
46+
#endif
47+
4348
#endif

include/foundation/builtins.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#define FOUNDATION_LIBC_ASSERT FOUNDATION_LIBC_ASSERT_DEFAULT
1313
#endif
1414

15+
#define FOUNDATION_LIBC_STATIC_ASSERT _Static_assert
16+
1517
#if defined(__clang__)
1618

1719
#define FOUNDATION_LIBC_NORETURN __attribute__((__noreturn__))

test/src/assert-validator.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ void assert_ok(void) {
2323
void assert_bad(void) {
2424
assert(0);
2525
}
26+
27+
void assert_static(void) {
28+
static_assert(sizeof(int) == sizeof(int), "int size check");
29+
}

0 commit comments

Comments
 (0)