diff options
Diffstat (limited to 'man3/static_assert.3')
-rw-r--r-- | man3/static_assert.3 | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/man3/static_assert.3 b/man3/static_assert.3 index 334e73d6d..86c6673dc 100644 --- a/man3/static_assert.3 +++ b/man3/static_assert.3 @@ -2,7 +2,7 @@ .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" -.TH static_assert 3 2023-01-26 "Linux man-pages 6.03" +.TH static_assert 3 2023-05-03 "Linux man-pages 6.05.01" .SH NAME static_assert, _Static_assert \- fail compilation if assertion is false .SH LIBRARY @@ -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 |