它是法律对双打的阵列使用的memset(0,)? [英] Is it legal to use memset(,0,) on array of doubles?

查看:136
本文介绍了它是法律对双打的阵列使用的memset(0,)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是合法的零数组双打(用memset(0,))或含有结构双打?

Is it legal to zero array of doubles (using memset(,0,)) or struct containing doubles ?

问题意味着两个不同的东西:

The question implies two different things:

(1)从图的C标准的点,是不是这个UB?
(于固定平台上,这可怎么UB ......它只是取决于浮动重新presentation这是所有的...)

(1) From the point of view of C standard, is this UB of not ? (on a fixed platform, how can this UB ... it just depends of floating representation that's all ...)

(2)从实际的角度来看:这是正常的Intel平台?
(不论是在说什么标准)。

(2) From practical point of view: is it ok on intel platform ? (no matter what standard is saying).

推荐答案

C99标准附件F说:

The C99 standard Annex F says:

本附录规定了的 IEC 60559浮点标准的C语言的支持。该
  IEC 60559浮点标准是专门二进制浮点运算
  微处理器系统,第二版(IEC 60559:1989)
的,previously指定
  的 IEC 559:1989 的和的 IEEE二进制浮点运算
  (ANSI / IEEE 754-1985)
的。的 IEEE标准为基数无关的浮点
  算术(ANSI / IEEE 854-1987)
的概括了二进制标准删除
  在基数和字长的依赖性。 IEC 60559一般指浮点
  标准,如IEC 60559的操作,IEC 60559等格式的实现,
  定义 __ __ STDC_IEC_559 应符合本附件的规定。哪里
  一个C语言和IEC 60559之间的结合表明,在IEC 60559规定的
  行为是由参考采用,除非另有说明。

This annex specifies C language support for the IEC 60559 floating-point standard. The IEC 60559 floating-point standard is specifically Binary floating-point arithmetic for microprocessor systems, second edition (IEC 60559:1989), previously designated IEC 559:1989 and as IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE 754−1985). IEEE Standard for Radix-Independent Floating-Point Arithmetic (ANSI/IEEE 854−1987) generalizes the binary standard to remove dependencies on radix and word length. IEC 60559 generally refers to the floating-point standard, as in IEC 60559 operation, IEC 60559 format, etc. An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex. Where a binding between the C language and IEC 60559 is indicated, the IEC 60559-specified behavior is adopted by reference, unless stated otherwise.

和,之后立即

的C浮点型符合IEC 60559的格式如下:

The C floating types match the IEC 60559 formats as follows:


      
  • 浮动类型IEC 60559单格式相匹配。

  •   
  • 双击类型IEC 60559双格式相匹配。

  •   
  • The float type matches the IEC 60559 single format.
  • The double type matches the IEC 60559 double format.

所以,如果IEC 60559是基本上IEEE 754-1985而这个指定8零字节的意思是0.0(如@大卫赫弗南说的),这意味着,如果你发现 __ __ STDC_IEC_559 定义你可以放心地做一个0.0初始化与 memset的

So, if IEC 60559 is basically IEEE 754-1985 and this specifies that 8 zero bytes mean 0.0 (as @David Heffernan said), this means that if you find __STDC_IEC_559__ defined you can safely do a 0.0 initialization with memset.

这篇关于它是法律对双打的阵列使用的memset(0,)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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