Skip to content

Commit a30c285

Browse files
committed
Manual; Try to clarify how automatic configuration works
1 parent c70fcf8 commit a30c285

1 file changed

Lines changed: 30 additions & 14 deletions

File tree

man/manual.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,39 +304,55 @@ In Linux you can use for instance the `bear` (build ear) utility to generate a c
304304

305305
# Preprocessor Settings
306306

307-
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.
307+
If you use `--project` then Cppcheck will automatically use the preprocessor settings in the imported project file and
308+
likely you don't have to configure anything extra.
308309

309-
## Defined and not defined
310+
If you don't use `--project` then a bit of manual preprocessor configuration might be required. However Cppcheck has
311+
automatic configuration of defines.
310312

311-
Here is a file that has 2 preprocessor configurations with A defined and without A defined:
313+
## Automatic configuration of -D
314+
315+
Here is a file that has 3 bugs (when x,y,z are assigned).
312316

313317
#ifdef A
314-
x = y;
318+
x=100/0;
319+
#ifdef B
320+
y=100/0;
321+
#endif
315322
#else
316-
x = z;
323+
z=100/0;
317324
#endif
318325

319-
By default Cppcheck will check all preprocessor configurations, except those that have #error in them.
320-
So the above code will by default be analyzed both with `A` defined and without `A` defined.
326+
Before the code is preprocessed, Cppcheck will by default look at what preprocessor conditions there are and generate
327+
a list of suitable preprocessor configurations. For the example code above, all bugs can be found if we check for
328+
instance the configurations "" and "A;B".
321329

322-
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.
323-
This is how compilers work. But you can use `--force` or `--max-configs` to override the number of configurations.
330+
Cppcheck will by default not try to check configurations that contain `#error`.
324331

325-
Check all configurations:
332+
Check all code:
326333

327334
cppcheck file.c
335+
=> All bugs are reported
336+
337+
### Limit automatic configurations
328338

329-
Only check the configuration A:
339+
To specify a preprocessor define you can use `-D`.
340+
341+
If there is an explicit configuration on the command line then Cppcheck will only that and nothing else.
330342

331343
cppcheck -DA file.c
344+
=> Only first bug is found
332345

333-
Check all configurations when macro A is defined:
346+
You can use `--force` to tell Cppcheck that you do want to check several configurations
334347

335348
cppcheck -DA --force file.c
349+
=> The first 2 bugs are found (if A is defined then the last bug never happens).
350+
351+
To exclude a certain define you can use `-U`. It tells Cppcheck that a macro is never defined. Example usage:
336352

337-
Another useful flag might be `-U`. It tells Cppcheck that a macro is not defined. Example usage:
353+
cppcheck -UA file.c
354+
=> Cppcheck will only report the last bug.
338355

339-
cppcheck -UX file.c
340356

341357
## Include paths
342358

0 commit comments

Comments
 (0)