What is the role of header files in C program while using static code analysis tool. If we forget to add header file how static code analysis tool will respond?
1 Answers
Obviously, the absence of a header file should affect code analysis. Many static analyzers will refuse to check a file that is not preprocessed.
A header file can provide information about types, macros, how functions are declared, and so on. How can the x = foo(y)
code be fully analyzed if it is impossible to understand what foo
is? No way. Perhaps we have a function call. Or maybe it's an explicit type conversion. Or even a big complex construction, if foo
is a tricky macro.
There are analyzers that can check the code, even if it cannot be preprocessed. But we must understand that they perform a very primitive code analysis. Such an analysis is based on a principle similar to searching for something with the help of regular expressions. But it is simply impossible to search for a huge number of defects based on regular expressions (or pattern-matching). Especially if we are talking about the C or C++ language. You can find more about this in the article "Static analysis and regular expressions".

- 1,083
- 6
- 17