Manual; Try to clarify how -D and -U works

This commit is contained in:
Daniel Marjamäki 2021-02-10 21:51:16 +01:00
parent d02a64c550
commit e8f36f6148
1 changed files with 10 additions and 14 deletions

View File

@ -312,6 +312,9 @@ automatic configuration of defines.
## Automatic configuration of preprocessor defines ## Automatic configuration of preprocessor defines
Cppcheck automatically test different combinations of preprocessor defines to achieve as high coverage in the analysis
as possible.
Here is a file that has 3 bugs (when x,y,z are assigned). Here is a file that has 3 bugs (when x,y,z are assigned).
#ifdef A #ifdef A
@ -328,25 +331,18 @@ Here is a file that has 3 bugs (when x,y,z are assigned).
#endif #endif
To find all bugs the code must be preprocessed both with "-DC" and with "-DA -DB -DC". The flag `-D` tells Cppcheck that a name is defined. There will be no Cppcheck analysis without this define.
The flag `-U` tells Cppcheck that a name is not defined. There will be no Cppcheck analysis with this define.
Cppcheck automatically determines what combinations of defines are necessary to analyze all the code. The example code
above will by default automatically be preprocessed and analyzed multiple times.
You can manually configure what combinations are checked with `-D`, `-U`, `--max-configs` and `--force`.
The flag `-D` tells Cppcheck that a name is defined.
The flag `-U` will tell Cppcheck that a name is not defined.
The flag `--force` and `--max-configs` is used to control how many combinations are checked. When `-D` is used, The flag `--force` and `--max-configs` is used to control how many combinations are checked. When `-D` is used,
Cppcheck will only check 1 configuration unless these are used. Cppcheck will only check 1 configuration unless these are used.
Example: Example:
cppcheck test.c => all bugs are found cppcheck test.c => test all configurations => all bugs are found
cppcheck -DA test.c => No bug is found (#error) cppcheck -DA test.c => only test configuration "-DA" => No bug is found (#error)
cppcheck -DA -DC test.c => The first bug is found cppcheck -DA -DC test.c => only test configuration "-DA -DC" => The first bug is found
cppcheck -UA test.c => The last bug is found cppcheck -UA test.c => The configuration "-DC" is tested => The last bug is found
cppcheck --force -DA test.c => The two first bugs are found cppcheck --force -DA test.c => All configurations with "-DA" are tested => The two first bugs are found
## Include paths ## Include paths