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/08/24 08:50:54 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 0e6edd39ec libs: fix visual studio Compiler Error C2124
0e6edd39ec is described below

commit 0e6edd39ecd46a6900d2aa8393ad44fddbf1ad4f
Author: chao.an <an...@xiaomi.com>
AuthorDate: Wed Aug 24 13:51:15 2022 +0800

    libs: fix visual studio Compiler Error C2124
    
    D:\code\incubator-nuttx\libs\libc\stdlib\lib_strtof.c(76,1): 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_strtof.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/libs/libc/stdlib/lib_strtof.c b/libs/libc/stdlib/lib_strtof.c
index 2c65bd2109..246a5183ad 100644
--- a/libs/libc/stdlib/lib_strtof.c
+++ b/libs/libc/stdlib/lib_strtof.c
@@ -73,7 +73,12 @@
 
 static inline int is_real(float x)
 {
-  const float infinite = 1.0F / 0.0F;
+  /* NOTE: Windows MSVC restrictions, MSVC doesn't allow division through a
+   * zero literal, but allows it through non-const variable set to zero
+   */
+
+  float divzero = 0.0F;
+  const float infinite = 1.0F / divzero;
   return (x < infinite) && (x >= -infinite);
 }
 
@@ -99,7 +104,13 @@ float strtof(FAR const char *str, FAR char **endptr)
   int n;
   int num_digits;
   int num_decimals;
-  const float infinite = 1.0F / 0.0F;
+
+  /* NOTE: Windows MSVC restrictions, MSVC doesn't allow division through a
+   * zero literal, but allows it through non-const variable set to zero
+   */
+
+  float divzero = 0.0F;
+  const float infinite = 1.0F / divzero;
 
   /* Skip leading whitespace */