使用memset零浮点数是否安全? [英] is it safe to zero float array with memset?

查看:466
本文介绍了使用memset零浮点数是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我必须将一个非常大的浮点阵列的所有元素初始化为

零。似乎memset(a,0,len)比简单循环更快。我只是想要知道这样做是否安全,因为我知道以这种方式初始化NULL指针是危险的。但是花车怎么样?


张乐

Hello,
I have to initialize all elements of a very big float point array to
zero. It seems memset(a, 0, len) is faster than a simple loop. I just
want to know whether it is safe to do so, since I know it''s danger to
initialize NULL pointers this way. But how about floats?

Zhang Le

推荐答案

69dbb24b2db3daad932c457ccc ... @gmail .com写道:
69dbb24b2db3daad932c457ccc...@gmail.com wrote:
你好,我必须将一个非常大的浮点阵列的所有元素初始化为零。似乎memset(a,0,len)比简单循环更快。我只是想知道这样做是否安全,因为我知道以这种方式初始化NULL指针是危险的。但浮点数怎么样?
Hello,
I have to initialize all elements of a very big float point array to
zero. It seems memset(a, 0, len) is faster than a simple loop. I just
want to know whether it is safe to do so, since I know it''s danger to
initialize NULL pointers this way. But how about floats?




是否动态分配了数组的内存?如果没有,你可以这样做:b
$ b浮动a [len] = {0};


使用memset设置零值只对整数类型是安全的,而不是
浮点类型或指针。


Robert Gamble



Is the memory for the array dynamically allocated? If not, you could
do this:
float a[len] = {0};

Using memset to set a value to zero is only safe on integer types, not
floating point types or pointers.

Robert Gamble


2005-07-22 09:59:28 -0500, 69 ********* @ gmail.com 说:
On 2005-07-22 09:59:28 -0500, 69***************************@gmail.com said:
你好,我必须将一个非常大的浮点阵列的所有元素初始化为零。似乎memset(a,0,len)比简单循环更快。我只是想知道这样做是否安全,因为我知道以这种方式初始化NULL指针是危险的。但是花车怎么样?

张乐
Hello,
I have to initialize all elements of a very big float point array to
zero. It seems memset(a, 0, len) is faster than a simple loop. I just
want to know whether it is safe to do so, since I know it''s danger to
initialize NULL pointers this way. But how about floats?

Zhang Le




这取决于。如果它是一个漂浮的数组是的,它是一个漂浮的数组*

你将所有的ptrs设置为NULL,无论如何都是安全的。

-

Sensei< se ****** @ tin.it>


cd / pub

更多啤酒



It depends. If it''s an array of float yes, of it''s an array of float*
you''re setting all ptrs to NULL, safe anyway.
--
Sensei <se******@tin.it>

cd /pub
more beer


Sensei写道:
2005-07-22 09:59:28 -0500, 69 ************** *************@gmail.com 说:
On 2005-07-22 09:59:28 -0500, 69***************************@gmail.com said:
你好,
我要初始化一个非常的所有元素大浮点阵列为零。似乎memset(a,0,len)比简单循环更快。我只是想知道这样做是否安全,因为我知道以这种方式初始化NULL指针是危险的。但是花车怎么样?

张乐
Hello,
I have to initialize all elements of a very big float point array to
zero. It seems memset(a, 0, len) is faster than a simple loop. I just
want to know whether it is safe to do so, since I know it''s danger to
initialize NULL pointers this way. But how about floats?

Zhang Le



这取决于。如果它是一个漂浮的数组是的,它是一个漂浮的数组*
你将所有的ptrs设置为NULL,无论如何都是安全的。



It depends. If it''s an array of float yes, of it''s an array of float*
you''re setting all ptrs to NULL, safe anyway.




你没什么意义。你说这取决于,然后你继续

说它在两种情况下都是安全的吗?好吧,你在所有方面都错了。

在任何一种情况下,C标准都不保证

这些场景中的任何一个是安全的。 NULL不一定是全位零,

浮点数也不需要使用它作为零的表示(或者

其他任何事情)。


Robert Gamble



You are making little sense. You said it depends, then you go on to
say that it is safe in either case? Well, you are wrong on all counts.
In either case there is no guarantee made by the C Standard that
either of these scenerios is safe. NULL need not be all-bits zero,
neither does float need to use this as a representation for zero (or
anything else for that matter).

Robert Gamble


这篇关于使用memset零浮点数是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆