Search code examples
objective-cif-statementcore-foundation

What is the point of these if(0) conditionals?


I was looking through some of the CFArray code after finding out it was open source and I found some, to me, strange code. What is the point of these "empty" if (0) conditionals? Is there some crazy benefit or is this just left over from something? This code is on line 957 of CFArray.c at GitHub.

if (0) {

} 
else if (NULL == array->_store) {
    if (0) {

    } 
    else if (0 <= futureCnt) {
           // blah blah
    }
}

Solution

  • They are most likely remnants from one of the many migrations of the codebase from platform to platform over its many year history. And, in general, if you have a tool that automatically and correctly migrates code from form A to form B, you generally don't want to manually muck with it after the fact because there is too much risk of introducing error.

    If you go way back in time to the transition from NeXTSTEP to OpenStep, there was a conversion technology called TOPS that was used to automate the conversion from API to API. A second variant was created to migrate from Objective-C to Java in the WebObjects days.

    It was, effectively, a sort of automated refactoring engine focused on transmogrifying API and language.

    TOPS was quite powerful and could easily be extended. It has been used quite effectively to perform various kinds of migrations -- version, API, style, etc.. -- both in the 3rd party community and inside of Apple/NeXT.

    (Personally, the last time I used TOPS was ~2002ish to migrate a 750,000 line NeXTSTEP 3.3 Objective-C++ application to Mac OS X 10.2. Required migrating from 3.3 -> 4.2, 4.2 -> PR1, PR1 -> 10.2. Was quite a challenge, but a lot of fun. There is a little more background here: http://www.cocoabuilder.com/archive/cocoa/221418-porting-from-windows-to-mac.html.)