sizeof (int) == sizeof (void*)?

后端 未结 10 905
有刺的猬
有刺的猬 2020-12-03 01:50

Is there an integer type with the same size as pointer? Guaranteed on all microarchitectures?

10条回答
  •  無奈伤痛
    2020-12-03 02:44

    The answer seems to be "no", but if all you need is a type that can act as both, you can use a union:

    union int_ptr_t {
        int i;
        void* p;
    };
    

提交回复
热议问题