type-props: Avoid a MSVC warning.
authorGurucharan Shetty <gshetty@nicira.com>
Fri, 17 Jul 2015 15:48:23 +0000 (08:48 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 31 Jul 2015 01:00:47 +0000 (18:00 -0700)
Currently, MSVC complains when you have a macro of the
form TYPE_MAXIMUM(uint64_t) because a part of macro becomes
~(uint64_t)0 << 64 with a warning:

C4293: '<<' : shift count negative or too big, undefined behavior.

This commit makes changes to the macro to prevent that warning.

Suggested-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
lib/type-props.h

index 8c83ea6..3c908a7 100644 (file)
 #define TYPE_IS_SIGNED(TYPE) ((TYPE) 1 > (TYPE) -1)
 #define TYPE_VALUE_BITS(TYPE) (sizeof(TYPE) * CHAR_BIT - TYPE_IS_SIGNED(TYPE))
 #define TYPE_MINIMUM(TYPE) (TYPE_IS_SIGNED(TYPE) \
-                            ? ~(TYPE)0 << TYPE_VALUE_BITS(TYPE) \
+                            ? ~(TYPE)0 << (sizeof(TYPE) * 8 - 1) \
                             : 0)
 #define TYPE_MAXIMUM(TYPE) (TYPE_IS_SIGNED(TYPE) \
-                            ? ~(~(TYPE)0 << TYPE_VALUE_BITS(TYPE)) \
+                            ? ~(~(TYPE)0 << (sizeof(TYPE) * 8 - 1)) \
                             : (TYPE)-1)
 
 /* Number of decimal digits required to format an integer of the given TYPE.