We could have achieved this task with a macro, but with a function, we have more control over the scope. We know that the only variable that can be modified by the function is the result variable.
Also, note that some flags need to be set both at compile and link time by setting CMAKE_REQUIRED_FLAGS for the check_<LANG>_compiler_flag function to report success correctly. This was the case for the sanitizers, as we discussed in Chapter 5, Configure-time and Build-time Operations, Recipe 7, Probing compiler flags.