1 /*******************************************************************
2 uLan Utilities Library - C library of basic reusable constructions
4 ul_utdefs.h - common defines used in uLan utilities library
6 *******************************************************************/
16 #if defined(_WIN32)&&defined(_MSC_VER)&&!defined(inline)
17 #define inline _inline
21 /* offset of structure field */
22 #define UL_OFFSETOF(_type,_member) \
23 ((size_t)&(((_type*)0)->_member))
26 #ifndef UL_CONTAINEROF
28 #define UL_CONTAINEROF(_ptr, _type, _member) ({ \
29 const typeof( ((_type *)0)->_member ) *__mptr = (_ptr); \
30 (_type *)( (char *)__mptr - UL_OFFSETOF(_type,_member) );})
32 #define UL_CONTAINEROF(_ptr, _type, _member) \
33 ((_type *)( (char *)_ptr - UL_OFFSETOF(_type,_member)))
35 #endif /*UL_CONTAINEROF*/
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 \
47 #endif /*ul_cyclic_gt*/
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 \
59 #endif /*ul_cyclic_ge*/
61 /* GNUC neat features */
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 #endif /*UL_ATTR_UNUSED*/
79 #ifndef UL_ATTR_UNUSED
80 #define UL_ATTR_PRINTF( format_idx, arg_idx )
81 #define UL_ATTR_SCANF( format_idx, arg_idx )
82 #define UL_ATTR_FORMAT( arg_idx )
83 #define UL_ATTR_NORETURN
85 #define UL_ATTR_UNUSED
86 #endif /*UL_ATTR_UNUSED*/
87 #endif /* !__GNUC__ */
93 #endif /* _UL_UTDEFS_H */