In C, are const variables guaranteed to be distinct in memory?

前端 未结 4 2235
死守一世寂寞
死守一世寂寞 2021-02-08 02:47

Speaking of string literals, the C99 standard says (6.4.5.6):

It is unspecified whether these arrays are distinct provided their elements have the appropr

4条回答
  •  广开言路
    2021-02-08 03:02

    As far as I'm aware, the Standard does not allow two named objects of any type to have the same address (except for union members). From 6.5.9/6:

    Two pointers compare equal if and only if both are null pointers, both are pointers to the same object...

    String literals are not const variables so your secondary question is moot, and I don't see what 32-bitness and endianness have to do with it.

提交回复
热议问题