Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
    }
}
like image 816
Halnry Avatar asked Jun 28 '13 20:06

Halnry


People also ask

What is a reason for zero conditional?

The zero conditional is used to make statements about the real world, and often refers to general truths, such as scientific facts. In these sentences, the time is now or always and the situation is real and possible.

What are the two uses of zero conditional?

The zero conditional is used to express: general habits. permanent truths/facts.

What tense is used if the condition is a zero conditional?

We use the Present Simple tense to talk about the condition. We also use the Present Simple tense to talk about the result. The important thing about the zero conditional is that the condition always has the same result.

Which is true about zero conditionals?

Zero conditional is used to talk about facts or situations which are always true. If you heat water, eventually it boils. If people don't eat or drink, they die.


2 Answers

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.)

like image 106
bbum Avatar answered Oct 10 '22 17:10

bbum


Likely, that was done to omit a codepath without incurring an unreachable code warning/error.

like image 35
LexLythius Avatar answered Oct 10 '22 18:10

LexLythius