Is there a particular reason when C / C++ were created that #elif was chosen over #elsif?
if ( ) {
} else if ( ) {
} else {
}
Fixed syntax
Is there a particular reason when C / C++ were created that #elif was chosen over #elsif?
if ( ) {
} else if ( ) {
} else {
}
Fixed syntax
Your example and your question don't match. There is no elsif
or even elseif
in C.
I don't know why the preprocessor uses #elif
rather than #elsif
, just the preference of Messrs. Kernighan and Richie, I suppose. The fact that they're different in perl (elsif) and python (elif) annoys me to no end.
The reason it is different is because the preprocessor is independent of the compiler. It may be a separate program that can be used on other programming languages and file types. Typically, the C compiler first runs the preprocessor on a file to generate a (temporary) new file and then compiles the new file (the new file can be saved with the appropriate compiler flags if needed). See the preprocessor information here.
As to why the preprocessor is different, I can only speculate but I would guess that since there is a space in the C else if
, they decided to imitate the UNIX sh 'elif'. Apparently the preprocessor in C came into existence in 1972 (taken from the article on B).
For a history of C by one of its creators, see http://cm.bell-labs.com/cm/cs/who/dmr/chist.html. The preprocessor was considered a seperate step, fitting in with UNIX's tradition of providing independent building blocks.