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*/
37 #ifndef UL_NOPSTATEMENT
38 #define UL_NOPSTATEMENT do { } while(0)
42 #define ul_cyclic_gt(x,y) \
43 ((sizeof(x)>=sizeof(long long))&&(sizeof(y)>=sizeof(long long))? \
44 (long long)((unsigned long long)(x)-(unsigned long long)(y))>0: \
45 (sizeof(x)>=sizeof(long))&&(sizeof(y)>=sizeof(long))? \
46 (long)((unsigned long)(x)-(unsigned long)(y))>0: \
47 (sizeof(x)>=sizeof(int))&&(sizeof(y)>=sizeof(int))? \
48 (int)((unsigned int)(x)-(unsigned int)(y))>0: \
49 (sizeof(x)>=sizeof(short))&&(sizeof(y)>=sizeof(short))? \
50 (short)((unsigned short)(x)-(unsigned short)(y))>0: \
51 (signed char)((unsigned char)(x)-(unsigned char)(y))>0 \
53 #endif /*ul_cyclic_gt*/
56 #define ul_cyclic_ge(x,y) \
57 ((sizeof(x)>=sizeof(long long))&&(sizeof(y)>=sizeof(long long))? \
58 (long long)((unsigned long long)(x)-(unsigned long long)(y))>=0: \
59 (sizeof(x)>=sizeof(long))&&(sizeof(y)>=sizeof(long))? \
60 (long)((unsigned long)(x)-(unsigned long)(y))>=0: \
61 (sizeof(x)>=sizeof(int))&&(sizeof(y)>=sizeof(int))? \
62 (int)((unsigned int)(x)-(unsigned int)(y))>=0: \
63 (sizeof(x)>=sizeof(short))&&(sizeof(y)>=sizeof(short))? \
64 (short)((unsigned short)(x)-(unsigned short)(y))>=0: \
65 (signed char)((unsigned char)(x)-(unsigned char)(y))>=0 \
67 #endif /*ul_cyclic_ge*/
69 /* GNUC neat features */
72 #ifndef UL_ATTR_UNUSED
73 #define UL_ATTR_PRINTF( format_idx, arg_idx ) \
74 __attribute__((format (printf, format_idx, arg_idx)))
75 #define UL_ATTR_SCANF( format_idx, arg_idx ) \
76 __attribute__((format (scanf, format_idx, arg_idx)))
77 #define UL_ATTR_FORMAT( arg_idx ) \
78 __attribute__((format_arg (arg_idx)))
79 #define UL_ATTR_NORETURN \
80 __attribute__((noreturn))
81 #define UL_ATTR_CONST \
82 __attribute__((const))
83 #define UL_ATTR_UNUSED \
84 __attribute__((unused))
85 #define UL_ATTR_CONSTRUCTOR \
86 __attribute__((constructor))
87 #define UL_ATTR_DESCRUCTOR \
88 __attribute__((destructor))
89 #define UL_ATTR_ALWAYS_INLINE \
90 __attribute__((always_inline))
91 #define UL_ATTR_WEAK \
93 #endif /*UL_ATTR_UNUSED*/
95 #ifndef UL_ATTR_UNUSED
96 #define UL_ATTR_PRINTF( format_idx, arg_idx )
97 #define UL_ATTR_SCANF( format_idx, arg_idx )
98 #define UL_ATTR_FORMAT( arg_idx )
99 #define UL_ATTR_NORETURN
100 #define UL_ATTR_CONST
101 #define UL_ATTR_UNUSED
102 #define UL_ATTR_CONSTRUCTOR
103 #define UL_ATTR_DESCRUCTOR
104 #define UL_ATTR_ALWAYS_INLINE
106 #endif /*UL_ATTR_UNUSED*/
107 #endif /* !__GNUC__ */
109 #ifndef UL_ATTR_REENTRANT
110 #if (!defined(SDCC) && !defined(__SDCC)) || defined(SDCC_z80) || defined(__SDCC_z80)
111 #define UL_ATTR_REENTRANT
113 #define UL_ATTR_REENTRANT __reentrant
115 #endif /*UL_ATTR_REENTRANT*/
121 #endif /* _UL_UTDEFS_H */