我正在使用 objc_[sg]etAssociatedObject()
,此函数使用内存地址作为键。如果我传递相同的字符串文字 - 例如"UIImageForTexture"
- 从两个不同的文件进入函数,两个字符串文字是否具有:
- 相同的内存地址?
- 不同的内存地址?
- 这取决于其他一些因素。
- 它是未定义的。
我可以通过将文字粘贴在文件中的某处并通过 extern
引用它来更明确地做到这一点,但我想知道我是否可以避免这样做。
最佳答案
这将是 C99 标准草案 6.4.5
String literals 段落 6 中的实现定义行为:
It is unspecified whether these arrays are distinct provided their elements have the appropriate values. If the program attempts to modify such an array, the behavior is undefined.
关于objective-c - 不同文件中的字符串文字是否具有相同的内存地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19505310/