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

前端 未结 7 1066
刺人心
刺人心 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

    Not quite what you're asking, but back in the 16-bit DOS/Windows days, you did have the distinction between a pointer and a far-pointer, the latter being 32-bits.

    I might have the syntax wrong...

    int *pInt = malloc(sizeof(int));
    int far *fpInt = _fmalloc(sizeof(int));
    
    printf("pInt: %d, fpInt: %d\n", sizeof(pInt), sizeof(fpInt));
    

    Output:

    pInt: 2, fpInt 4

提交回复
热议问题