diff --git a/configure.ac b/configure.ac
index 192ab16cf..c85da0c29 100644
--- a/configure.ac
+++ b/configure.ac
@@ -180,6 +180,16 @@ else
     fi
 fi
 
+# Get the size of long int
+AC_CACHE_CHECK([Size of long int],
+[iperf3_cv_sizeof_long],
+AC_RUN_IFELSE(
+  [AC_LANG_PROGRAM([[#include <stdio.h>]],
+                   [[fprintf(stderr, "%zd", sizeof(long)); return(0)]])],
+  [iperf3_cv_sizeof_long=`./conftest$EXEEXT 2>&1`],
+  [AC_MSG_ERROR(Failed to compile and run size of long test)]))
+AC_DEFINE_UNQUOTED([SIZE_OF_LONG_INT], $iperf3_cv_sizeof_long, [Size of long int.])
+
 # Check for TCP_CONGESTION sockopt (believed to be Linux and FreeBSD only)
 AC_CACHE_CHECK([TCP_CONGESTION socket option],
 [iperf3_cv_header_tcp_congestion],
diff --git a/src/cjson.c b/src/cjson.c
index 02d8d6001..249259709 100644
--- a/src/cjson.c
+++ b/src/cjson.c
@@ -94,13 +94,13 @@
 # include <inttypes.h>
 #else
 # ifndef PRIu64
-#  if sizeof(long) == 8
+#  if SIZE_OF_LONG_INT == 8
 #   define PRIu64		"lu"
 #  else
 #   define PRIu64		"llu"
 #  endif
 # ifndef PRId64
-#  if sizeof(long) == 8
+#  if SIZE_OF_LONG_INT == 8
 #   define PRId64		"ld"
 #  else
 #   define PRId64		"lld"
diff --git a/src/iperf.h b/src/iperf.h
index a5eea4237..57e5df7e3 100644
--- a/src/iperf.h
+++ b/src/iperf.h
@@ -55,7 +55,7 @@
 # include <inttypes.h>
 #else
 # ifndef PRIu64
-#  if sizeof(long) == 8
+#  if SIZE_OF_LONG_INT == 8
 #   define PRIu64		"lu"
 #  else
 #   define PRIu64		"llu"
diff --git a/src/iperf_locale.c b/src/iperf_locale.c
index 41d78cb5c..0457d3171 100644
--- a/src/iperf_locale.c
+++ b/src/iperf_locale.c
@@ -85,7 +85,7 @@
 # include <inttypes.h>
 #else
 # ifndef PRId64
-#  if sizeof(long) == 8
+#  if SIZE_OF_LONG_INT == 8
 #   define PRId64		"ld"
 #  else
 #   define PRId64		"lld"
diff --git a/src/iperf_udp.c b/src/iperf_udp.c
index 5f69ee366..3f1cf46ee 100644
--- a/src/iperf_udp.c
+++ b/src/iperf_udp.c
@@ -52,7 +52,7 @@
 # include <inttypes.h>
 #else
 # ifndef PRIu64
-#  if sizeof(long) == 8
+#  if SIZE_OF_LONG_INT == 8
 #   define PRIu64		"lu"
 #  else
 #   define PRIu64		"llu"