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

前端 未结 8 939
太阳男子
太阳男子 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:25

    They're not guaranteed to be the same size, although on the platforms I have experience with they usually are.

    C 2011 online draft:

    6.2.5 Types
    ...
    28     A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.48) 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.
    48) The same representation and alignment requirements are meant to imply interchangeability as arguments to functions, return values from functions, and members of unions.

提交回复
热议问题