gpt4 book ai didi

c - 可以将地址强制转换为整数吗?

转载 作者:太空宇宙 更新时间:2023-11-04 05:07:42 24 4
gpt4 key购买 nike

Queue queue = createQueue(); //queue to store int values
Node *node = getNode(8);
enQueue(queue, (int)node);//storing an address in the int

..... some other statements ....

Node *root = (Node *) deQueue(queue);//typecasting an int to address
Node *left = root->left;

在上面的代码中,队列可以存储整数值,而地址正在存储分配给它。它会产生任何问题吗?

在什么情况下或任何架构中,在 int 中存储地址可能会出现问题?

请举例说明。

最佳答案

what are the situations or any architecture where storing address in an int can be problematic?

指针大于 int 的架构。即,大多数 64 位系统。您可以使用类型 long 或更好的 intptr_t

关于c - 可以将地址强制转换为整数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11708851/

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