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

标签 c casting

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/

相关文章:

c# - 为什么我不能将 linq 的 Cast 与用户定义的转换一起使用,但我可以将它与 Select 调用一起使用?

c - 如何在没有内存泄漏的情况下删除 C 中的前导/尾随空格

c - 在 YACC 中分配字符串时出错

c - 相邻的字符和字符串文字标记

c++ - 转换运算符转换为仅模板参数不同的类?

在Python中将列表列表的所有元素转换为 float

postgresql - 如何将表参数传递给此函数?

c - 汇编函数不会更改从 c 发送的数组中的值

c - fgetc内部如何工作

C# 不同的转换方式——(T)obj vs obj as T