manual: preprocessor configuration, platform, standard
This commit is contained in:
parent
fac8e52379
commit
dc5e93a103
|
@ -217,6 +217,48 @@ In Linux you can use for instance the `bear` (build ear) utility to generate a c
|
||||||
|
|
||||||
bear make
|
bear make
|
||||||
|
|
||||||
|
# Preprocessor Settings
|
||||||
|
|
||||||
|
If you use `--project` then Cppcheck will use the preprocessor settings from the imported project. Otherwise you'll probably want to configure the include paths, defines, etc.
|
||||||
|
|
||||||
|
## Defined and not defined
|
||||||
|
|
||||||
|
Here is a file that has 2 preprocessor configurations (with A defined and without A defined):
|
||||||
|
|
||||||
|
#ifdef A
|
||||||
|
x = y;
|
||||||
|
#else
|
||||||
|
x = z;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
By default Cppcheck will check all preprocessor configurations (except those that have #error in them). So the above code will by default be analyzed both with `A` defined and without `A` defined.
|
||||||
|
|
||||||
|
You can use `-D` and/or `-U` to change this. When you use `-D`, cppcheck will by default only check the given configuration and nothing else. This is how compilers work. But you can use `--force` or `--max-configs` to override the number of configurations.
|
||||||
|
|
||||||
|
Check all configurations:
|
||||||
|
|
||||||
|
cppcheck file.c
|
||||||
|
|
||||||
|
Only check the configuration A:
|
||||||
|
|
||||||
|
cppcheck -DA file.c
|
||||||
|
|
||||||
|
Check all configurations when macro A is defined
|
||||||
|
|
||||||
|
cppcheck -DA --force file.c
|
||||||
|
|
||||||
|
Another useful flag might be `-U`. It tells Cppcheck that a macro is not defined. Example usage:
|
||||||
|
|
||||||
|
cppcheck -UX file.c
|
||||||
|
|
||||||
|
## Include paths
|
||||||
|
|
||||||
|
To add an include path, use `-I`, followed by the path.
|
||||||
|
|
||||||
|
Cppcheck's preprocessor basically handles includes like any other preprocessor. However, while other preprocessors stop working when they encounter a missing header, cppcheck will just print an information message and continues parsing the code.
|
||||||
|
|
||||||
|
The purpose of this behaviour is that cppcheck is meant to work without necessarily seeing the entire code. Actually, it is recommended to not give all include paths. While it is useful for cppcheck to see the declaration of a class when checking the implementation of its members, passing standard library headers is highly discouraged because it will result in worse results and longer checking time. For such cases, .cfg files (see below) are the better way to provide information about the implementation of functions and types to cppcheck.
|
||||||
|
|
||||||
# Platform
|
# Platform
|
||||||
|
|
||||||
You should use a platform configuration that match your target.
|
You should use a platform configuration that match your target.
|
||||||
|
@ -245,49 +287,19 @@ You can also create your own custom platform configuration in a XML file. Here i
|
||||||
</sizeof>
|
</sizeof>
|
||||||
</platform>
|
</platform>
|
||||||
|
|
||||||
# Preprocessor Settings
|
# C/C++ Standard
|
||||||
|
|
||||||
If you use `--project` then Cppcheck will use the preprocessor settings from the imported project. Otherwise you'll probably want to configure the include paths, defines, etc.
|
Cppcheck assumes that the code is compatible with the latest C/C++ standard but you can override this.
|
||||||
|
|
||||||
## Defines
|
The available options are:
|
||||||
|
* c89: C code is C89 compatible
|
||||||
Here is a file that has 2 preprocessor configurations (with A defined and without A defined):
|
* c99: C code is C99 compatible
|
||||||
|
* c11: C code is C11 compatible (default)
|
||||||
#ifdef A
|
* c++03: C++ code is C++03 compatible
|
||||||
x = y;
|
* c++11: C++ code is C++11 compatible
|
||||||
#else
|
* c++14: C++ code is C++14 compatible
|
||||||
x = z;
|
* c++17: C++ code is C++17 compatible
|
||||||
#endif
|
* c++20: C++ code is C++20 compatible (default)
|
||||||
|
|
||||||
By default Cppcheck will check all preprocessor configurations (except those that have #error in them). So the above code will by default be analyzed both with `A` defined and without `A` defined.
|
|
||||||
|
|
||||||
You can use `-D` to change this. When you use `-D`, cppcheck will by default only check the given configuration and nothing else. This is how compilers work. But you can use `--force` or `--max-configs` to override the number of configurations.
|
|
||||||
|
|
||||||
Check all configurations:
|
|
||||||
|
|
||||||
cppcheck file.c
|
|
||||||
|
|
||||||
Only check the configuration A:
|
|
||||||
|
|
||||||
cppcheck -DA file.c
|
|
||||||
|
|
||||||
Check all configurations when macro A is defined
|
|
||||||
|
|
||||||
cppcheck -DA --force file.c
|
|
||||||
|
|
||||||
Another useful flag might be `-U`. It tells Cppcheck that a macro is not defined. Example usage:
|
|
||||||
|
|
||||||
cppcheck -UX file.c
|
|
||||||
|
|
||||||
That will mean that X is not defined. Cppcheck will not check what happens when X is defined.
|
|
||||||
|
|
||||||
## Include paths
|
|
||||||
|
|
||||||
To add an include path, use `-I`, followed by the path.
|
|
||||||
|
|
||||||
Cppcheck's preprocessor basically handles includes like any other preprocessor. However, while other preprocessors stop working when they encounter a missing header, cppcheck will just print an information message and continues parsing the code.
|
|
||||||
|
|
||||||
The purpose of this behaviour is that cppcheck is meant to work without necessarily seeing the entire code. Actually, it is recommended to not give all include paths. While it is useful for cppcheck to see the declaration of a class when checking the implementation of its members, passing standard library headers is highly discouraged because it will result in worse results and longer checking time. For such cases, .cfg files (see below) are the better way to provide information about the implementation of functions and types to cppcheck.
|
|
||||||
|
|
||||||
# Suppressions
|
# Suppressions
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue