]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_utdefs.h
Corrected delete_all for static version of GSA.
[ulut.git] / ulut / ul_utdefs.h
1 /*******************************************************************
2   uLan Utilities Library - C library of basic reusable constructions
3
4   ul_utdefs.h   - common defines used in uLan utilities library
5
6  *******************************************************************/
7
8
9 #ifndef _UL_UTDEFS_H
10 #define _UL_UTDEFS_H
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #if defined(_WIN32)&&defined(_MSC_VER)&&!defined(inline)
17 #define inline _inline
18 #endif
19
20 #ifndef UL_OFFSETOF
21 /* offset of structure field */
22 #define UL_OFFSETOF(_type,_member) \
23                 ((size_t)&(((_type*)0)->_member))
24 #endif /*UL_OFFSET*/
25
26 #ifndef UL_CONTAINEROF
27 #ifdef  __GNUC__
28 #define UL_CONTAINEROF(_ptr, _type, _member) ({ \
29         const typeof( ((_type *)0)->_member ) *__mptr = (_ptr); \
30         (_type *)( (char *)__mptr - UL_OFFSETOF(_type,_member) );})
31 #else /*!__GNUC__*/
32 #define UL_CONTAINEROF(_ptr, _type, _member) \
33         ((_type *)( (char *)_ptr - UL_OFFSETOF(_type,_member)))
34 #endif /*__GNUC__*/
35 #endif /*UL_CONTAINEROF*/
36
37 #ifndef ul_cyclic_gt
38 #define ul_cyclic_gt(x,y) \
39         ((sizeof(x)>=sizeof(long long))&&(sizeof(y)>=sizeof(long long))? \
40                 (long long)((long long)(x)-(long long)(y))>0: \
41          (sizeof(x)>=sizeof(long))&&(sizeof(y)>=sizeof(long))? \
42                 (long)((long)(x)-(long)(y))>0: /* x,y casts to suppress warnings only*/ \
43          (sizeof(x)>=sizeof(int))&&(sizeof(y)>=sizeof(int))?(int)((x)-(y))>0: \
44          (sizeof(x)>=sizeof(short))&&(sizeof(y)>=sizeof(short))?(short)((x)-(y))>0: \
45          (signed char)((x)-(y))>0 \
46         )
47 #endif /*ul_cyclic_gt*/
48
49 #ifndef ul_cyclic_ge
50 #define ul_cyclic_ge(x,y) \
51         ((sizeof(x)>=sizeof(long long))&&(sizeof(y)>=sizeof(long long))? \
52                 (long long)((long long)(x)-(long long)(y))>=0: \
53          (sizeof(x)>=sizeof(long))&&(sizeof(y)>=sizeof(long))? \
54                 (long)((long)(x)-(long)(y))>=0: /* x,y casts to suppress warnings only*/ \
55          (sizeof(x)>=sizeof(int))&&(sizeof(y)>=sizeof(int))?(int)((x)-(y))>=0: \
56          (sizeof(x)>=sizeof(short))&&(sizeof(y)>=sizeof(short))?(short)((x)-(y))>=0: \
57          (signed char)((x)-(y))>=0 \
58         )
59 #endif /*ul_cyclic_ge*/
60
61 /* GNUC neat features */
62
63 #ifdef  __GNUC__
64 #ifndef UL_ATTR_UNUSED
65 #define UL_ATTR_PRINTF( format_idx, arg_idx )   \
66   __attribute__((format (printf, format_idx, arg_idx)))
67 #define UL_ATTR_SCANF( format_idx, arg_idx )    \
68   __attribute__((format (scanf, format_idx, arg_idx)))
69 #define UL_ATTR_FORMAT( arg_idx )               \
70   __attribute__((format_arg (arg_idx)))
71 #define UL_ATTR_NORETURN                        \
72   __attribute__((noreturn))
73 #define UL_ATTR_CONST                           \
74   __attribute__((const))
75 #define UL_ATTR_UNUSED                          \
76   __attribute__((unused))
77 #define UL_ATTR_CONSTRUCTOR                     \
78   __attribute__((constructor))
79 #define UL_ATTR_DESCRUCTOR                      \
80   __attribute__((destructor))
81 #define UL_ATTR_ALWAYS_INLINE                   \
82   __attribute__((always_inline))
83 #endif  /*UL_ATTR_UNUSED*/
84 #else   /* !__GNUC__ */
85 #ifndef UL_ATTR_UNUSED
86 #define UL_ATTR_PRINTF( format_idx, arg_idx )
87 #define UL_ATTR_SCANF( format_idx, arg_idx )
88 #define UL_ATTR_FORMAT( arg_idx )
89 #define UL_ATTR_NORETURN
90 #define UL_ATTR_CONST
91 #define UL_ATTR_UNUSED
92 #define UL_ATTR_CONSTRUCTOR
93 #define UL_ATTR_DESCRUCTOR
94 #define UL_ATTR_ALWAYS_INLINE
95 #endif  /*UL_ATTR_UNUSED*/
96 #endif  /* !__GNUC__ */
97
98 #ifdef __cplusplus
99 } /* extern "C"*/
100 #endif
101
102 #endif /* _UL_UTDEFS_H */