Browse code

- added MAX_UVAR_VALUE(), MAX_int(a,b) MIN_int(a,b)

Andrei Pelinescu-Onciul authored on 05/06/2007 13:53:41
Showing 1 changed files
... ...
@@ -40,6 +40,7 @@
40 40
  * 2005-11-29 reverse_hex2int/int2reverse_hex switched to unsigned int (andrei)
41 41
  * 2005-12-09 added msgid_var (andrei)
42 42
  * 2007-05-14 added get_sys_ver() (andrei)
43
+ * 2007-06-05 added MAX_UVAR_VALUE(), MAX_int(a,b) MIN_int(a,b) (andrei)
43 44
  */
44 45
 
45 46
 
... ...
@@ -117,6 +118,27 @@
117 117
 #define ROUND_SHORT(s) ROUND2TYPE(s, short)
118 118
 
119 119
 
120
+/* params: v - either a variable name, structure member or a type
121
+ * returns an unsigned long containing the maximum possible value that will
122
+ * fit in v, if v is unsigned or converted to an unsigned version
123
+ * example: MAX_UVAR_VALUE(unsigned short); MAX_UVAR_VALUE(i);
124
+ *  MAX_UVAR_VALUE(((struct foo*)0)->bar) */
125
+#define MAX_UVAR_VALUE(v) \
126
+	(((unsigned long)(-1))>>((sizeof(unsigned long)-sizeof(v))*8UL))
127
+
128
+
129
+#define MIN_int(a, b) (((a)<(b))?(a):(b))
130
+#define MAX_int(a, b) (((a)>(b))?(a):(b))
131
+
132
+#if 0
133
+#define MIN_int(a, b) ((b)+(((a)-(b))& -((a)<(b))))
134
+#define MAX_int(a, b) ((a)-(((a)-(b))& -((b)>(a))))
135
+
136
+/* depend on signed right shift result which depends on the compiler */
137
+#define MIN_int(a, b) ((b)+(((a)-(b))&(((a)-(b))>>(sizeof(int)*8-1))))
138
+#define MAX_int(a, b) ((a)-(((a)-(b))&(((a)-(b))>>(sizeof(int)*8-1))))
139
+#endif
140
+
120 141
 
121 142
 /* links a value to a msgid */
122 143
 struct msgid_var{