diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-10-21 14:31:54 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-10-22 01:33:20 +0200 |
commit | 66032ef489e19292b06773e5f44531a7b44c23c5 (patch) | |
tree | 399152dcb7ece3c8da5cd6d38ccfdaeae123bf73 /src/basic/macro.h | |
parent | units: add initrd-cryptsetup.target (diff) | |
download | systemd-66032ef489e19292b06773e5f44531a7b44c23c5.tar.xz systemd-66032ef489e19292b06773e5f44531a7b44c23c5.zip |
macro: introduce POINTER_MAX as define for (void*) -1
Just add a safer, prettier way to write (void*) -1, that doesn't rely on
two's complement, but uses the correct underlying C constructs.
Diffstat (limited to 'src/basic/macro.h')
-rw-r--r-- | src/basic/macro.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h index 7aa51fe939..d0ddb369ca 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -554,10 +554,13 @@ static inline int __coverity_check_and_return__(int condition) { #define STRV_MAKE(...) ((char**) ((const char*[]) { __VA_ARGS__, NULL })) #define STRV_MAKE_EMPTY ((char*[1]) { NULL }) -/* Iterates through a specified list of pointers. Accepts NULL pointers, but uses (void*) -1 as internal marker for EOL. */ -#define FOREACH_POINTER(p, x, ...) \ - for (typeof(p) *_l = (typeof(p)[]) { ({ p = x; }), ##__VA_ARGS__, (void*) -1 }; \ - p != (typeof(p)) (void*) -1; \ +/* Pointers range from NULL to POINTER_MAX */ +#define POINTER_MAX ((void*) UINTPTR_MAX) + +/* Iterates through a specified list of pointers. Accepts NULL pointers, but uses POINTER_MAX as internal marker for EOL. */ +#define FOREACH_POINTER(p, x, ...) \ + for (typeof(p) *_l = (typeof(p)[]) { ({ p = x; }), ##__VA_ARGS__, POINTER_MAX }; \ + p != (typeof(p)) POINTER_MAX; \ p = *(++_l)) /* Define C11 thread_local attribute even on older gcc compiler |