它是安全的强制转换为int为void指针和回再次诠释? [英] Is it safe to cast an int to void pointer and back to int again?
问题描述
在C和/或C ++:?是安全投int类型为void指针和回再次诠释
In C and/or C++: is it safe to cast an int to void pointer and back to int again?
href=\"http://stackoverflow.com/questions/3567905/c-is-it-safe-to-cast-pointer-to-int-and-later-back-to-pointer-again\">C++:它是安全投指针为int,后来回再次指针?。
Based on the question "C++: Is it safe to cast pointer to int and later back to pointer again?".
推荐答案
在大多数现代司空见惯的机器,大概。
In most modern-day commonplace machines, probably.
不过,我敢打赌,有一些模糊的编译器或配置(例如,一个16位寻址,使用32位的整数运算计算机)不是这样的。
However, I'd bet that there is some obscure compiler or configuration (say, a 16-bit addressed machine that uses 32-bit integer arithmetic) where that is not the case.
一个 uintptr_t形式保证同时容纳,不过,如果你想这样使用该类型。
A uintptr_t is guaranteed to hold both, though, so use that type if you want to.
这篇关于它是安全的强制转换为int为void指针和回再次诠释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!