1. Why doesn't the following code crashes?
Line 286: projectfile.cpp
if (target && ft == ftHeader && compiler && compiler->GetSwitches().supportsPCH)
Because if compiler is NULL all following checks are *not* done. The
if statement exits early if the fist boolean is false... at least this applies to GCC. Other compiler *might* handle this different.
2. Why compiler is getting NULL value? At least it should get a Compiler.
Actually this can easily happen. Suppose you create a copy of a compiler and setup a project based on that. Now if you open the project on another PC where this compiler (the copy) isn't setup then the compiler will usually be NULL. Another option is that the one or other (like me ;-)) might have base compilers integrated that do not exist at all. In that case opening such a project would result in the compiler being NULL, too.
In the end there is another option: Disable the compiler plugin and the compiler will always be NULL. ;-)
BTW: You can easily simulate these cases by modifying a C::B project file and setting the compiler to an invalid string like:
<Option compiler="does_not_exist" />... and/or disable the compiler plugin. This reminds me that at the time Yiannis implemented the plugin activate/de-activate facility we were hunting quite some bugs with missing checks for a valid compiler. Maybe we should repeat this step from time to time. ;-)
With regards, Morten.