Author: DheerajK_81 Version: **
Translation - Japanese: PSoC Creator での GCC ウォーニング診断設定 - KBA225431- Community Translated (JA)
Question: How can the GCC warnings be diagnosed in PSoC Creator™?
PSoC Creator uses the GCC compiler to diagnose the code for warnings or errors and displays them in the notice list. GCC allows you to selectively enable or disable certain types of diagnostics and change the type of the diagnostic[MB1] [DK2] . The warnings can be diagnosed using:
- Command line option of the compiler
- Pragma GCC diagnostics
Method 1: Using Command Line Option of the Compiler
The command line uses custom flags which can diagnose the warnings during runtime. The different custom flags can be found here. This method is a global setting and applies to the entire code. Add the custom flags to the build settings as shown in Figure 1.
Figure 1. Adding Custom Flags
Method 2: Using Pragma GCC Diagnostics
Pragma processor directives are used to change the kind of diagnostic. You can read more about diagnostic pragmas here. This method is mainly used to diagnose certain sections of code though it can be used as a global setting too. These pragmas are added in the code as shown here:
<kind> can be either error, warning, or ignored
<option> is a string that matches the command line option
#pragma GCC diagnostic ignored “-Wunused-variable” //This will ignore all warnings related to unused variables
Frequently Asked Questions:
How can I disable the warnings displayed in the Output window and the Notice List?
You can use the custom flag option “-w” in the build settings while using the command line option of the compiler.
How can the warnings within a certain section of the code be diagnosed?
Pragma offers the push and pop options which specify the beginning and end of the section of the code to be diagnosed.
#pragma GCC diagnostic push //Line 1
#pragma GCC diagnostic ignored “-Wunused-variable”//Line 2
#pragma GCC diagnostic pop //Line 20
In this example, code within lines 3 to 20 which has any unused variables will be ignored and no warnings will be thrown. Similarly, you can modify the example to ignore the errors in the specified section of the code by replacing ignored with error.
What is the option field to be used in the pragma syntax?
When the code is compiled in PSoC Creator, every warning comes with a pragma option as in
Figure 2. Pragma Options
The highlighted section in represents the pragma option.
How can all warnings be converted into errors?
Use the flag “-Werror” in the build settings.
How can a specific warning, for example, unused variable be converted into an error?
If you are using command line option, use the flag “-Werror=unused-variable” in the build settings.
If you are using the pragma GCC diagnostics, use the line:
#pragma GCC diagnostic error “-Wunused-variable”
Which method has higher priority?
Both methods prevail on the diagnostic priority; ignored > warning > error. The method that has the highest diagnostic will prevail.
How can a warning be disabled and transferred to the Notice List?
PSoC Creator has a system that monitors compiler output and uses regular expressions to match toolchain output to detect errors and warnings. The system for detecting new forms of output (for example, to generate info notices for #pragma diagnostic) is not available [MB1] [DK2] and hence we cannot generate info notices for the notice list.