From 5bd179b19977b37c5349428a1d2d1124b6e575fd Mon Sep 17 00:00:00 2001 From: Wang Renxin Date: Thu, 17 Oct 2019 11:27:58 +0800 Subject: [PATCH] *refactored `_set_real_with_hex` to avoid `c4310` (vc). --- core/my_basic.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/core/my_basic.c b/core/my_basic.c index c46455b..66b33b0 100755 --- a/core/my_basic.c +++ b/core/my_basic.c @@ -945,20 +945,25 @@ static _object_t* _exp_assign = 0; #define _set_real_with_hex(__r, __i) \ do { \ if(sizeof(__r) == sizeof(unsigned char)) { \ - unsigned char __b = (unsigned char)__i; \ - memcpy(&(__r), &__b, sizeof(__r)); \ + union { unsigned char i; real_t r; } __u; \ + __u.i = __i; \ + __r = __u.r; \ } else if(sizeof(__r) == sizeof(unsigned short)) { \ - unsigned short __b = (unsigned short)__i; \ - memcpy(&(__r), &__b, sizeof(__r)); \ + union { unsigned short i; real_t r; } __u; \ + __u.i = __i; \ + __r = __u.r; \ } else if(sizeof(__r) == sizeof(unsigned)) { \ - unsigned __b = (unsigned)__i; \ - memcpy(&(__r), &__b, sizeof(__r)); \ + union { unsigned i; real_t r; } __u; \ + __u.i = __i; \ + __r = __u.r; \ } else if(sizeof(__r) == sizeof(unsigned long)) { \ - unsigned long __b = (unsigned long)__i; \ - memcpy(&(__r), &__b, sizeof(__r)); \ + union { unsigned long i; real_t r; } __u; \ + __u.i = __i; \ + __r = __u.r; \ } else if(sizeof(__r) == sizeof(unsigned long long)) { \ - unsigned long long __b = (unsigned long long)__i; \ - memcpy(&(__r), &__b, sizeof(__r)); \ + union { unsigned long long i; real_t r; } __u; \ + __u.i = __i; \ + __r = __u.r; \ } else { \ mb_assert(0 && "Invalid real number precision."); \ } \