reactor-c
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
generics.h
Go to the documentation of this file.
1
35#ifndef GENERICS_H
36#define GENERICS_H
37
39#if defined __has_builtin
41#define var __auto_type
42
44#define lf_is_same_type(a, b) __builtin_types_compatible_p(__typeof__(a), __typeof__(b))
45
47#define lf_is_same(typename, b) __builtin_types_compatible_p(typename, __typeof__(b))
48
50#define lf_is_type_equal(typename_a, typename_b) __builtin_types_compatible_p(typename_a, typename_b)
51
53#define lf_is_pointer_or_array(p) (__builtin_classify_type(p) == 5)
54
55#define lf_decay(p) (&*__builtin_choose_expr(lf_is_pointer_or_array(p), p, NULL))
56
58#define lf_is_pointer(p) lf_is_same_type(p, lf_decay(p))
59
61#define lf_get_pointer(p) __builtin_choose_expr(lf_is_pointer(p), p, &p)
62
64#define lf_to_left_type(left, right) \
65 __builtin_choose_expr(lf_is_pointer_or_array(left), \
66 __builtin_choose_expr(lf_is_pointer_or_array(right), (right), &(right)), \
67 __builtin_choose_expr(lf_is_pointer_or_array(right), *(right), (right)))
68
69#else // buitin are not available
70
71#define var
72#define lf_is_same_type(a, b)
73#define lf_is_same(typename, b)
74#define lf_is_pointer_or_array(p)
75#define lf_decay(p)
76#define lf_is_pointer(p)
77#define lf_get_pointer(p)
78#define lf_to_left_type(left, right)
79
80#endif // __has_builtin
81
82#endif // GENERICS_H