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

前端 未结 12 1796
梦如初夏
梦如初夏 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:37

    Use uintptr_t from "stdint.h" or from "boost/stdint.h". It is guaranteed to have enough storage for a pointer.

提交回复
热议问题