Could it be the case that sizeof(T*) != sizeof(const T*)?

前端 未结 4 908
遥遥无期
遥遥无期 2021-02-06 20:30

I\'m arguing with my boss about this. They say \"Yes they can be different.\"

Is it possible that sizeof(T*) != sizeof(const T*) for a type T?<

4条回答
  •  野性不改
    2021-02-06 20:46

    Hmm, this is highly esoterical, but I'm thinking that theoretically there could be an architecture which has, say, 256 bytes of RAM in address 0 and, say, some kilobytes of ROM in higher addresses. And there could be a compiler that would create a 8-bit pointer for int *i because 8 bits is enough to hold the address of any object in the highly limited RAM area and any mutable object of course is implicitly known to be in the RAM area. Pointers of type const int *i would need 16 bits so that they could point to any location in the address space. The 8-bit pointer int *i is castable to a 16-bit pointer const int *i (but not vice versa) so the castability requirement of C standard would be satisfied.

    But if there's such an architecture in existense, I'd sure like to see it (but not write code for it) :)

提交回复
热议问题