snej / MYUtilities

Objective-C Cocoa utility functions/methods I can't live without
Other
58 stars 21 forks source link

Fixing a compilation error where NSStrings where being compared using pointer comparison. #2

Closed drekka closed 12 years ago

drekka commented 12 years ago

A small fix. My compiler settings would not let this through so I had to change it to use isEqualToString:.

snej commented 12 years ago

Huh — what error did you get exactly? There's nothing wrong with the code ... the function is static and gets called with a parameter of kWarningPrefix, so a pointer comparison is valid.

(Also, minor nit: your inserted line isn't indented properly.)

drekka commented 12 years ago

I'm getting "direct comparison of a string literal has undefined behavior" which I found referenced in http://root.cern.ch/svn/root/trunk/interpreter/llvm/src/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td

which seems to be based around @"x" == @"y" or obj == @"x" scenarios. I don't know if this is new or not. If I understand your code correctly you are attempting to check that two pointers are pointing to the same address as a way of asking if both variables contain a reference to the same constant string. That makes sense to me and I presume it would be faster so I'm not sure why Clang is defending against it.