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

后端 未结 10 928
有刺的猬
有刺的猬 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:39

    The standard solution to this problem is to write a small program which checks the sizes of all int types (short int, int, long int) and compares them to void*. If there is a match, it emits a piece of code which defines the intptr type. You can put this in a header file and use the new type.

    It's simple to include this code in the build process (using make, for example)

提交回复
热议问题