diff options
Diffstat (limited to 'include/libc-internal.h')
-rw-r--r-- | include/libc-internal.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/libc-internal.h b/include/libc-internal.h index e5fd533..0c0fa02 100644 --- a/include/libc-internal.h +++ b/include/libc-internal.h @@ -34,4 +34,20 @@ extern void __libc_thread_freeres (void); /* Define and initialize `__progname' et. al. */ extern void __init_misc (int, char **, char **); +/* 1 if 'type' is a pointer type, 0 otherwise. */ +# define __pointer_type(type) (__builtin_classify_type ((type) 0) == 5) + +/* __intptr_t if P is true, or T if P is false. */ +# define __integer_if_pointer_type_sub(T, P) \ + __typeof__ (*(0 ? (__typeof__ (0 ? (T *) 0 : (void *) (P))) 0 \ + : (__typeof__ (0 ? (__intptr_t *) 0 : (void *) (!(P)))) 0)) + +/* __intptr_t if EXPR has a pointer type, or the type of EXPR otherwise. */ +# define __integer_if_pointer_type(expr) \ + __integer_if_pointer_type_sub(__typeof__ ((__typeof__ (expr)) 0), \ + __pointer_type (__typeof__ (expr))) + +/* Cast an integer or a pointer VAL to integer with proper type. */ +# define cast_to_integer(val) ((__integer_if_pointer_type (val)) (val)) + #endif /* _LIBC_INTERNAL */ |