尝试记录此函数的结果时,我会不断获取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 - 尝试返回uint64_t编号时为EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16762621/

10-09 18:44