libdecnumber中decNumberCopy()的结构大小不同?

libdecnumber中decNumberCopy()的结构大小不同?,c,C,我在一个项目中使用libdecnumber,库中有一个特殊的小函数,它的文档让我有点困惑。函数为decNumberCopy() 以下是decNumber /* The size (integer data type) of each unit is determined by the */ /* number of digits it will hold. */ #if DECDPUN<=2 #define d

我在一个项目中使用libdecnumber,库中有一个特殊的小函数,它的文档让我有点困惑。函数为
decNumberCopy()

以下是
decNumber

/* The size (integer data type) of each unit is determined by the   */
/* number of digits it will hold.                                   */
#if   DECDPUN<=2
  #define decNumberUnit uint8_t
#elif DECDPUN<=4
  #define decNumberUnit uint16_t
#else
  #define decNumberUnit uint32_t
#endif
/* The number of units needed is ceil(DECNUMDIGITS/DECDPUN)         */
#define DECNUMUNITS ((DECNUMDIGITS+DECDPUN-1)/DECDPUN)

/* The data structure... */
typedef struct {
  int32_t digits;      /* Count of digits in the coefficient; >0    */
  int32_t exponent;    /* Unadjusted exponent, unbiased, in         */
                       /* range: -1999999997 through 999999999      */
  uint8_t bits;        /* Indicator bits (see above)                */
                       /* Coefficient, from least significant unit  */
  decNumberUnit lsu[DECNUMUNITS];
} decNumber;
/*每个单元的大小(整数数据类型)由*/
/*它将保留的位数*/

#如果DECDPUN,我猜来自
decNumber.h
的这条评论应该可以解释一些事情:

  /* Notes: */
  /* 1. If digits is > DECDPUN then there will be more than one */
  /*    decNumberUnits immediately following the first element of lsu. */
  /*    These contain the remaining (more significant) digits of the */
  /*    number, and may be in the lsu array, or may be guaranteed by */
  /*    some other mechanism (such as being contained in another */
  /*    structure, or being overlaid on dynamically allocated storage). */
换句话说,decNumber结构包含
decnumbernit lsu[decnuminits]
数组以保存“默认”位数,但如果需要,库会将数组扩展到该大小以外

更新:


快速浏览一下
decNumber.c
(我不知道它离最新版本有多近)看起来好像他们还没有实现任何对存储超出
decNumber.lsu[decnuminits]
所能保存的数字的支持。看起来
decNumberCopy()
更关心的是只复制使用过的
lsu[decnuminits]
元素,而不是整个元素(作为优化和/或允许测试来检测数据的可能损坏)。

我想
decnumerits.h
中的这条注释应该解释一下:

  /* Notes: */
  /* 1. If digits is > DECDPUN then there will be more than one */
  /*    decNumberUnits immediately following the first element of lsu. */
  /*    These contain the remaining (more significant) digits of the */
  /*    number, and may be in the lsu array, or may be guaranteed by */
  /*    some other mechanism (such as being contained in another */
  /*    structure, or being overlaid on dynamically allocated storage). */
换句话说,decNumber结构包含
decnumbernit lsu[decnuminits]
数组以保存“默认”位数,但如果需要,库会将数组扩展到该大小以外

更新:


快速浏览一下
decNumber.c
(我不知道它离最新版本有多近)看起来好像他们还没有实现任何对存储超出
decNumber.lsu[decnuminits]
所能保存的数字的支持。看起来
decNumberCopy()
更关心的是只复制使用过的
lsu[decnuminits]
元素,而不是整个元素(作为优化和/或允许测试来检测数据可能的损坏)。

感谢@Rup添加了#libdecnumber标记。感谢@Rup添加了#libdecnumber标记。