Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define SIZE_OF_LONG_INT to replace sizeof(long) in #if #1636

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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, "%d", sizeof(long)); return(0)]])],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request! I got a compiler warning with macOS / Clang on this line (line 188) where it complained of a mismatch between the %d format specifier (which takes an int) and sizeof(long), which is a long. If I changed the %d to %zd then this seems to work correctly.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's all kinda pointless.
<inttypes.h> is in c99, c99 is supported everywhere (that's why issue gone unnoticed for 10 years), and "%zd" is from c99 too. Besides, AC_RUN_IFELSE breaks on cross-compilation (you need check that fails on compilation stage), etc.
Just use `<inttypes.h>' unconditionally and be done.

[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],
Expand Down
4 changes: 2 additions & 2 deletions src/cjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/iperf_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down