]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_utdefs.h
Minor uLUt enhancements for C89 conformance from other projects.
[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                 ((int)&(((_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 /* GNUC neat features */
38
39 #ifdef  __GNUC__
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*/
54 #else   /* !__GNUC__ */
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
60 #define UL_ATTR_CONST
61 #define UL_ATTR_UNUSED
62 #endif  /*UL_ATTR_UNUSED*/
63 #endif  /* !__GNUC__ */
64
65 #ifdef __cplusplus
66 } /* extern "C"*/
67 #endif
68
69 #endif /* _UL_UTDEFS_H */