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/