sizeof void pointer

前端 未结 5 635
无人及你
无人及你 2020-12-24 07:24

why is sizeof void pointer 2 ?

5条回答
  •  无人及你
    2020-12-24 08:06

    Per the online C standard (n1256 draft):

    6.2.5 Types
    ...
    27 A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.39) Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements.

    As to why void and char pointers have a size of 2 on your system, I suspect that's because you're on a 16-bit platform.

提交回复
热议问题