C++: Is it safe to cast pointer to int and later back to pointer again?

前端 未结 12 1825
梦如初夏
梦如初夏 2020-11-28 11:38

Is it safe to cast pointer to int and later back to pointer again?

How about if we know if the pointer is 32 bit long and int is 32 bit long?

long* j         


        
12条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 12:42

    If your going to be doing any system portable casting, you need to use something like Microsofts INT_PTR/UINT_PTR, the safety after that relies on the target platforms and what you intend doing to the INT_PTR. generally for most arithmatic char* or uint_8* works better while being typesafe(ish)

提交回复
热议问题