Warning: Geeky Post

I spent a few hours this morning tracking down a problem that was so annoying and stupid that I wanted to post something on the off chance it will be helpful to someone in the future…

In MemoryMiner when a new Photo object is created, its “creationDateString” ivar is set to “????-??-??”. When the details of the file being cataloged become known, the value is typically re-set using a precise date/time value read from the photo file itself (e.g. from the EXIF data put there by a digital camera, or from IPTC data put there using a media manager application). In the case where no date is known (e.g. with a scanned photo), then the user can supply whatever components of the date they know.

The code for dealing with creation dates has remained unchanged for a long time. This past Sunday, I released a new test build of MemoryMiner 2.0, and much to my horror, this morning, while doing some testing with scanned photos, the creationDateString ended up in the database as “??~~??” which is decidedly not a good thing. WTF?!!

Turns out, the problem was due to a change I’d recently made in one of my XCode projects, notably to use the C99 “dialect”. I’d made this change after integrating an open-source class (Stig Brautaset’s most excellent Obj-C JSON parser, to be precise) that uses a C99-style “for::” loop.

As a consequence of using C99, my default creation date sting was being preprocessed as a Trigraph, which means each “??-” was being converted to a tilde character: “~”. The solution was to switch to using the GNU99 C dialect.

Now, I’ve been writing Obj-C code since the late-90’s (having made the jump from my first foray into writing software using Webscript, an interpreted version of Obj-C used with WebObjects), and until today, I’ve never known, much less cared, what a C trigraph is. It makes me recall a comment in this blog post on Theocaco from two years ago:

“From an implementation (Apple) perspective, Objective-C rests on top of raw C, but from the developer-user’s perspective, they’re worlds apart. You can write plenty of Cocoa code without knowing what asprintf or wchar_t is.”

You can say that again!

Many many thanks to Rainer Brockerhoff for helping me get to the bottom of this.

Leave a Reply