summaryrefslogtreecommitdiffstats
path: root/man3/static_assert.3
diff options
context:
space:
mode:
Diffstat (limited to 'man3/static_assert.3')
-rw-r--r--man3/static_assert.318
1 files changed, 9 insertions, 9 deletions
diff --git a/man3/static_assert.3 b/man3/static_assert.3
index f24837576..e01ff1d47 100644
--- a/man3/static_assert.3
+++ b/man3/static_assert.3
@@ -67,7 +67,7 @@ The following program uses the macro to get the size of an array safely.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+\&
/*
* This macro behaves like static_assert(), failing to
* compile if its argument is not true. However, it always
@@ -83,33 +83,33 @@ The following program uses the macro to get the size of an array safely.
} \e
) \e
)
-
+\&
#define is_same_type(a, b) \e
__builtin_types_compatible_p(typeof(a), typeof(b))
-
+\&
#define is_array(arr) (!is_same_type((arr), &*(arr)))
#define must_be_array(arr) must_be(is_array(arr))
-
+\&
#define sizeof_array(arr) (sizeof(arr) + must_be_array(arr))
#define nitems(arr) (sizeof((arr)) / sizeof((arr)[0]) \e
+ must_be_array(arr))
-
+\&
int foo[10];
int8_t bar[sizeof_array(foo)];
-
+\&
int
main(void)
{
for (size_t i = 0; i < nitems(foo); i++) {
foo[i] = i;
}
-
+\&
memcpy(bar, foo, sizeof_array(bar));
-
+\&
for (size_t i = 0; i < nitems(bar); i++) {
printf("%d,", bar[i]);
}
-
+\&
exit(EXIT_SUCCESS);
}
.EE