Previously, we would use the compiler's default C version, which defaults
to gnu89 for GCC < 5, gnu11 for GCC > 5, and c11 for clang, but might even
differ per distro.
One of the reasons to accept the gnu89 default of GCC < 4.9, was that MSVC
didn't support c99. But in MSVC 2015, MS finanally fixed that.
Having to support c89 in the codebase occasionally forces us to write less
readable code, for example by forcing all declaration to be at the starting
of a block (which includes 'for loop initial declarations').
Let's be clear about what standard we obey, and stop punishing ourselves
with c89/gnu89. Let's switch the master branch to c99.
v2: don't try to detect pedantic mode based on __STRICT_ANSI__, since that
will be defined when using -std=c99.
v3: only set -std=c99 if there is no -std= already present in CFLAGS
Signed-off-by: Steffan Karger <steffan@karger.me>
Acked-by: David Sommerseth <davids@openvpn.net>
Message-Id: 1472760870-11769-1-git-send-email-steffan@karger.me
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg00194.html
Signed-off-by: David Sommerseth <davids@openvpn.net>
... | ... |
@@ -1125,10 +1125,16 @@ if test "${enable_pkcs11}" = "yes"; then |
1125 | 1125 |
) |
1126 | 1126 |
fi |
1127 | 1127 |
|
1128 |
+# Set -std=c99 unless user already specified a -std= |
|
1129 |
+case "${CFLAGS}" in |
|
1130 |
+ *-std=*) ;; |
|
1131 |
+ *) CFLAGS="${CFLAGS} -std=c99" ;; |
|
1132 |
+esac |
|
1133 |
+ |
|
1128 | 1134 |
if test "${enable_pedantic}" = "yes"; then |
1129 | 1135 |
enable_strict="yes" |
1130 | 1136 |
CFLAGS="${CFLAGS} -pedantic" |
1131 |
- test "${WIN32}" != "yes" && CFLAGS="${CFLAGS} -std=c99" |
|
1137 |
+ AC_DEFINE([PEDANTIC], [1], [Enable pedantic mode]) |
|
1132 | 1138 |
fi |
1133 | 1139 |
if test "${enable_strict}" = "yes"; then |
1134 | 1140 |
CFLAGS="${CFLAGS} -Wall -Wno-unused-parameter -Wno-unused-function" |
... | ... |
@@ -384,16 +384,13 @@ |
384 | 384 |
* Pedantic mode is meant to accomplish lint-style program checking, |
385 | 385 |
* not to build a working executable. |
386 | 386 |
*/ |
387 |
-#ifdef __STRICT_ANSI__ |
|
388 |
-# define PEDANTIC 1 |
|
387 |
+#ifdef PEDANTIC |
|
389 | 388 |
# undef HAVE_CPP_VARARG_MACRO_GCC |
390 | 389 |
# undef HAVE_CPP_VARARG_MACRO_ISO |
391 | 390 |
# undef EMPTY_ARRAY_SIZE |
392 | 391 |
# define EMPTY_ARRAY_SIZE 1 |
393 | 392 |
# undef inline |
394 | 393 |
# define inline |
395 |
-#else |
|
396 |
-# define PEDANTIC 0 |
|
397 | 394 |
#endif |
398 | 395 |
|
399 | 396 |
/* |