gpt4 book ai didi

c++ - 这是有效的内存对齐吗?如果没有,应该如何解决?

转载 作者:行者123 更新时间:2023-11-28 06:23:04 55 4
gpt4 key购买 nike

decNumber.h:

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]; // decNumberUnit is int16_t and DECNUMUNITS is 1
} decNumber;

测试.cpp:

decNumber a,b,c;

当我打印 a、b 和 c 的地址时,这是我得到的:

a:0x7fff0d7a9858 到 0x7fff0d7a9864

b:0x7fff0d7a9864 到 0x7fff0d7a9870

c:0x7fff0d7a987c 到 0x7fff0d7a9888

a和b之间0x7fff0d7a9864的字节重叠是否有效?该程序最终会遇到段错误。为什么?

非常感谢任何帮助!

最佳答案

Is the byte overlap of 0x7fff0d7a9864 between a and b valid?

没有字节重叠。例如,0 到 5 表示 [0, 1, 2, 3, 4],5 到 10 表示 [5, 6, 7, 8, 9]。

This program eventually runs into a segmentation fault. Why?

不可能。问题中的程序不完整,无法编译。它不会导致段错误,因为没有可以运行的程序。

关于c++ - 这是有效的内存对齐吗?如果没有,应该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29017413/

55 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com