Are all data pointers the same size in one platform for all data types?

前端 未结 8 941
太阳男子
太阳男子 2020-11-22 16:33

Are char*, int*, long* or even long long* of same size (on a given platform)?

8条回答
  •  醉酒成梦
    2020-11-22 17:23

    There is no such guarantee in either C or C++ ISO standards, but in practice, I've yet to see a platform where this doesn't hold.

    Note that regardless of this, reinterpret_cast'ing one pointer to another will more often than not lead to U.B., with a few exceptions (void*, and unsigned char* for PODs). So would any union tricks. So the obvious question is: why would you care?

提交回复
热议问题