Are there any platforms where pointers to different types have different sizes?

前端 未结 7 1166
刺人心
刺人心 2020-11-22 12:40

The C standard allows pointers to different types to have different sizes, e.g. sizeof(char*) != sizeof(int*) is permitted. It does, however, require that if a

7条回答
  •  旧巷少年郎
    2020-11-22 12:58

    Therefore, it follows logically that sizeof(void*) >= sizeof(T*) for all types T, correct?

    That doesn't necessarily follow, since sizeof is about the storage representation, and not all bit-patterns have to be valid values. I think you could write a conformant implementation where sizeof(int*) == 8, sizeof(void*) == 4, but there are no more than 2^32 possible values for an int*. Not sure why you'd want to.

提交回复
热议问题