-#define get_integer_bitsize(type,where) \
- { type x = 1; \
- int bits = 0; \
- loop \
- { if (x==0) break; \
- x = x+x; \
- bits++; \
- if (bits==1000) { bits = -1; break; } \
- } \
- where = bits; \
+#define get_unsigned_integer_bitsize(type,where) \
+ { type x = 1; \
+ int bits = 0; \
+ loop { \
+ if (x==0) break; \
+ x = x+x; \
+ bits++; \
+ if (bits==1000) { bits = -1; break; } \
+ } \
+ where = bits; \
+ }
+#define get_signed_integer_bitsize(type,unsigned_type,where) \
+ { /* Signed integer overflow is "undefined behaviour" in C99, and gcc-4.3 \
+ (without -fwrapv option) actually does weird things when signed integer \
+ overflow occurs. Therefore perform the addition on the unsigned type. \
+ Drawback: This will not detect cases where the signed type has more bits\
+ than the unsigned type but the same size according to sizeof. Blech. */ \
+ type x = 1; \
+ int bits = 0; \
+ loop { \
+ if (x==0) break; \
+ x = (unsigned_type)x + (unsigned_type)x;\
+ bits++; \
+ if (bits==1000) { bits = -1; break; } \
+ } \
+ where = bits; \