gpt4 book ai didi

ios - EXC_BAD_ACCESS 尝试返回 uint64_t 数字时

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:03:11 27 4
gpt4 key购买 nike

当我尝试记录此函数的结果时,我一直收到 EXC_BAD_ACCESS 吗?我做错了什么?

-(uint64_t) rand64bitNum {
uint32_t left = arc4random();
uint32_t right = arc4random();
uint64_t randNum = 0;
memcpy(&randNum, &left, sizeof(left));
uint16_t offset = sizeof(left);
memcpy(&randNum+offset, &right, sizeof(right));
return randNum;
}

最佳答案

&randnum+offset 并不像您认为的那样;指针加法以被指向的事物为单位执行。所以你可能需要 (char *)&randnum + offset

关于ios - EXC_BAD_ACCESS 尝试返回 uint64_t 数字时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16762621/

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