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 ((int)&(((_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 /* GNUC neat features */
40 #ifndef UL_ATTR_UNUSED
41 #define UL_ATTR_PRINTF( format_idx, arg_idx ) \
42 __attribute__((format (printf, format_idx, arg_idx)))
43 #define UL_ATTR_SCANF( format_idx, arg_idx ) \
44 __attribute__((format (scanf, format_idx, arg_idx)))
45 #define UL_ATTR_FORMAT( arg_idx ) \
46 __attribute__((format_arg (arg_idx)))
47 #define UL_ATTR_NORETURN \
48 __attribute__((noreturn))
49 #define UL_ATTR_CONST \
50 __attribute__((const))
51 #define UL_ATTR_UNUSED \
52 __attribute__((unused))
53 #endif /*UL_ATTR_UNUSED*/
55 #ifndef UL_ATTR_UNUSED
56 #define UL_ATTR_PRINTF( format_idx, arg_idx )
57 #define UL_ATTR_SCANF( format_idx, arg_idx )
58 #define UL_ATTR_FORMAT( arg_idx )
59 #define UL_ATTR_NORETURN
61 #define UL_ATTR_UNUSED
62 #endif /*UL_ATTR_UNUSED*/
63 #endif /* !__GNUC__ */
69 #endif /* _UL_UTDEFS_H */