You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/09/25 20:40:14 UTC
[incubator-nuttx] branch master updated: libs: fix visual studio Compiler Error C2124
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 09c006b9c8 libs: fix visual studio Compiler Error C2124
09c006b9c8 is described below
commit 09c006b9c84c19dcad883faf366b70cca304872a
Author: chao an <an...@xiaomi.com>
AuthorDate: Sun Sep 25 23:19:54 2022 +0800
libs: fix visual studio Compiler Error C2124
D:\code\incubator-nuttx\libs\libc\stdlib\lib_strtod.c: error C2124: divide or mod by zero
Windows MSVC restrictions, MSVC doesn't allow division through a
zero literal, but allows it through non-const variable set to zero
Reference:
https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2124?view=msvc-170
Signed-off-by: chao an <an...@xiaomi.com>
---
libs/libc/stdlib/lib_strtod.c | 15 +++++++++++++--
libs/libc/stdlib/lib_strtold.c | 15 +++++++++++++--
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/libs/libc/stdlib/lib_strtod.c b/libs/libc/stdlib/lib_strtod.c
index fe8e48ff4b..529bf9d1c6 100644
--- a/libs/libc/stdlib/lib_strtod.c
+++ b/libs/libc/stdlib/lib_strtod.c
@@ -71,7 +71,12 @@
static inline int is_real(double x)
{
- const double infinite = 1.0 / 0.0;
+ /* NOTE: Windows MSVC restrictions, MSVC doesn't allow division through a
+ * zero literal, but allows it through non-const variable set to zero
+ */
+
+ const double divzero = 0.0;
+ const double infinite = 1.0 / divzero;
return (x < infinite) && (x >= -infinite);
}
@@ -101,7 +106,13 @@ double strtod(FAR const char *str, FAR char **endptr)
int n;
int num_digits;
int num_decimals;
- const double infinite = 1.0 / 0.0;
+
+ /* NOTE: Windows MSVC restrictions, MSVC doesn't allow division through a
+ * zero literal, but allows it through non-const variable set to zero
+ */
+
+ const double divzero = 0.0;
+ const double infinite = 1.0 / divzero;
/* Skip leading whitespace */
diff --git a/libs/libc/stdlib/lib_strtold.c b/libs/libc/stdlib/lib_strtold.c
index cd569561d2..a043412d04 100644
--- a/libs/libc/stdlib/lib_strtold.c
+++ b/libs/libc/stdlib/lib_strtold.c
@@ -71,7 +71,12 @@
static inline int is_real(long double x)
{
- const long double infinite = 1.0L / 0.0L;
+ /* NOTE: Windows MSVC restrictions, MSVC doesn't allow division through a
+ * zero literal, but allows it through non-const variable set to zero
+ */
+
+ const long double divzero = 0.0L;
+ const long double infinite = 1.0L / divzero;
return (x < infinite) && (x >= -infinite);
}
@@ -101,7 +106,13 @@ long double strtold(FAR const char *str, FAR char **endptr)
int n;
int num_digits;
int num_decimals;
- const long double infinite = 1.0L / 0.0L;
+
+ /* NOTE: Windows MSVC restrictions, MSVC doesn't allow division through a
+ * zero literal, but allows it through non-const variable set to zero
+ */
+
+ const long double divzero = 0.0L;
+ const long double infinite = 1.0L / divzero;
/* Skip leading whitespace */