]> rtime.felk.cvut.cz Git - ulut.git/blob - ulut/ul_utdefs.h
Updates to support SDCC 3.1.4+ new build-in defines.
[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                 ((size_t)&(((_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_NOPSTATEMENT
38 #define UL_NOPSTATEMENT do { } while(0)
39 #endif
40
41 #ifndef ul_cyclic_gt
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 \
52         )
53 #endif /*ul_cyclic_gt*/
54
55 #ifndef ul_cyclic_ge
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 \
66         )
67 #endif /*ul_cyclic_ge*/
68
69 /* GNUC neat features */
70
71 #ifdef  __GNUC__
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                            \
92   __attribute__((weak))
93 #endif  /*UL_ATTR_UNUSED*/
94 #else   /* !__GNUC__ */
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
105 #define UL_ATTR_WEAK
106 #endif  /*UL_ATTR_UNUSED*/
107 #endif  /* !__GNUC__ */
108
109 #ifndef UL_ATTR_REENTRANT
110 #if (!defined(SDCC) && !defined(__SDCC)) || defined(SDCC_z80) || defined(__SDCC_z80)
111   #define UL_ATTR_REENTRANT
112 #else
113   #define UL_ATTR_REENTRANT __reentrant
114 #endif
115 #endif /*UL_ATTR_REENTRANT*/
116
117 #ifdef __cplusplus
118 } /* extern "C"*/
119 #endif
120
121 #endif /* _UL_UTDEFS_H */