On May 20, 2005, at 10:04 AM, James Bucanek wrote: I ran into something odd today.
I'm working on a Cocoa application that contained the following code
if ([[anItem title] isEqualToString:@"Save As…"])
I had been compiling this for months under Xcode 1.5/gcc 3, and for several weeks using Xcode 2.0/gcc 4.
For the purposes of this discussion let's assume that the points of ellipsis are U+2026, HORIZONTAL ELLIPSIS, encoded perhaps as UTF8 0xE2 0x80 0xA6. Ore even MacRoman "…". But something with a high bit set, not three periods. Today, I decided to try cross-compiling the code using the 10.3.9 SDK. When I did, the file would no longer compile (I have "treat warnings as errors" set). I get the compiler error
warning: non-ASCII character in CFString literal
Here's the weird thing (to me, at least). If I select any regression SDK (10.2.8, 10.3.9, even 10.4.0) I get this warning. But if I switch to "Current Mac OS" the warning goes away.
So I have three questions:
1) How does the SDK selection affect the compiler behavior/flags?
Generally it doesn't. It only affects the paths in which the compiler searches for headers and the linker searches for link libraries. It does set some preprocessor macros that declares what version of compatibility you expect, so some #ifdef paths may be taken using an SDK that are not taken otherwise, but no, GCC flags are not affected by SDK choice.
2) Is there a gcc flag to ignore this warning? (It obviously isn't a limitation of the gcc 3 compiler, or the 10.3.x system as I've been building and running this same code under Xcode 1.5 & OS X 10.3 for months.) If there is such a switch, where the heck did you find it? ;) I've done every search I could think of, both on the gcc.gnu.org site, Apple's site, the gcc man pages, and the Internet in general.
Try -wnonportable-cfstrings. I'm somewhat astonished that it's completely undocumented. You can read the source and checkin comments at http://www.mail-archive.com/email@hidden/msg00172.html
3) Thinking that at some point I might need to include non-ASCII character in a literal CFString, how does one do it? I tried @"string\u2026", but got an error that unicode characters were only supported in C99. Can I use a UTF-8 sequence? I don't think so. You're probably going to have to define a C string constant that contains the escaped UTF-8 character sequence and create your CFString on the fly with CFStringCreateWithCStringNoCopy:
if ([[anItem title] isEqualToString: CFStringCreateWithCStringNoCopy(kCFAllocatorNull, "Save As\226\128\172", kCFStringEncodingUTF8, kCFAllocatorNull])
|