Avoid printf type modifiers not supported by MSVC C runtime library.
[sliver-openvswitch.git] / lib / util.h
index 91dc0a5..fbab74c 100644 (file)
@@ -212,6 +212,23 @@ is_pow2(uintmax_t x)
  * (void *). This is to suppress the alignment warning issued by clang. */
 #define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
 
+/* Use "%"PRIuSIZE to format size_t with printf(). */
+#ifdef _WIN32
+#define PRIdSIZE "Id"
+#define PRIiSIZE "Ii"
+#define PRIoSIZE "Io"
+#define PRIuSIZE "Iu"
+#define PRIxSIZE "Ix"
+#define PRIXSIZE "IX"
+#else
+#define PRIdSIZE "zd"
+#define PRIiSIZE "zi"
+#define PRIoSIZE "zo"
+#define PRIuSIZE "zu"
+#define PRIxSIZE "zx"
+#define PRIXSIZE "zX"
+#endif
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
@@ -287,7 +304,7 @@ void ignore(bool x OVS_UNUSED);
 
 int log_2_floor(uint32_t);
 int log_2_ceil(uint32_t);
-unsigned int popcount(uint32_t);
+unsigned int count_1bits(uint64_t);
 
 /* Returns the number of trailing 0-bits in 'n'.  Undefined if 'n' == 0. */
 #if __GNUC__ >= 4
@@ -306,21 +323,6 @@ raw_ctz(uint64_t n)
 int raw_ctz(uint64_t n);
 #endif
 
-#if __GNUC__ >= 4
-static inline int
-popcount64(uint64_t n)
-{
-    return __builtin_popcountll(n);
-}
-#else
-/* Defined using the 32-bit counterparts. */
-static inline int
-popcount64(uint64_t n)
-{
-    return popcount(n) + popcount(n >> 32);
-}
-#endif
-
 /* Returns the number of trailing 0-bits in 'n', or 32 if 'n' is 0. */
 static inline int
 ctz(uint32_t n)