]> rtime.felk.cvut.cz Git - can-usb1.git/blob - ulan/host/libs4c/ulut/ul_utdefs.h
Initializing repo
[can-usb1.git] / ulan / host / libs4c / 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 #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 #endif  /*UL_ATTR_UNUSED*/
78 #else   /* !__GNUC__ */
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
84 #define UL_ATTR_CONST
85 #define UL_ATTR_UNUSED
86 #endif  /*UL_ATTR_UNUSED*/
87 #endif  /* !__GNUC__ */
88
89 #ifdef __cplusplus
90 } /* extern "C"*/
91 #endif
92
93 #endif /* _UL_UTDEFS_H */