~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/global.h

  • Committer: Stewart Smith
  • Date: 2009-03-18 00:29:24 UTC
  • mto: (942.1.10 mordred)
  • mto: This revision was merged to the branch mainline in revision 945.
  • Revision ID: stewart@flamingspork.com-20090318002924-gixoh4t5mhbw8qyz
make set_if_bigger typesafe for C and C++. Fix up everywhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
134
134
extern char _dig_vec_upper[];
135
135
extern char _dig_vec_lower[];
136
136
 
 
137
#ifdef __cplusplus
 
138
template <class T> void set_if_bigger(T &a, const T &b)
 
139
{
 
140
  if (a < b)
 
141
    a=b;
 
142
}
 
143
 
 
144
template <class T> void set_if_smaller(T &a, const T &b)
 
145
{
 
146
  if (a > b)
 
147
    a=b;
 
148
}
 
149
#else
 
150
#ifdef __GNUC__
 
151
#define set_if_bigger(a,b) do {                 \
 
152
  const typeof(a) _a = (a);                     \
 
153
  const typeof(b) _b = (b);                     \
 
154
  (void) (&_a == &_b);                          \
 
155
  if ((a) < (b)) (a)=(b);                       \
 
156
  } while(0)
 
157
#define set_if_smaller(a,b) do {                \
 
158
  const typeof(a) _a = (a);                     \
 
159
  const typeof(b) _b = (b);                     \
 
160
  (void) (&_a == &_b);                          \
 
161
  if ((a) > (b)) (a)=(b);                       \
 
162
  } while(0)
 
163
 
 
164
#else
137
165
#define set_if_bigger(a,b)  do { if ((a) < (b)) (a)=(b); } while(0)
138
 
 
139
166
#define set_if_smaller(a,b) do { if ((a) > (b)) (a)=(b); } while(0)
 
167
#endif
 
168
#endif
 
169
 
140
170
#define array_elements(A) ((size_t) (sizeof(A)/sizeof(A[0])))
141
171
 
142
172
/* Some types that is different between systems */