You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: man/manual.md
+30-14Lines changed: 30 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -304,39 +304,55 @@ In Linux you can use for instance the `bear` (build ear) utility to generate a c
304
304
305
305
# Preprocessor Settings
306
306
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.
308
309
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.
310
312
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).
312
316
313
317
#ifdef A
314
-
x = y;
318
+
x=100/0;
319
+
#ifdef B
320
+
y=100/0;
321
+
#endif
315
322
#else
316
-
x = z;
323
+
z=100/0;
317
324
#endif
318
325
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".
321
329
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`.
324
331
325
-
Check all configurations:
332
+
Check all code:
326
333
327
334
cppcheck file.c
335
+
=> All bugs are reported
336
+
337
+
### Limit automatic configurations
328
338
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.
330
342
331
343
cppcheck -DA file.c
344
+
=> Only first bug is found
332
345
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
334
347
335
348
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:
336
352
337
-
Another useful flag might be `-U`. It tells Cppcheck that a macro is not defined. Example usage:
0 commit comments