warn_unusedvar. NXP CodeWarrior Development Studio
Reklama
Reklama
Chapter 31 Pragmas for Diagnostic Messages
This check helps you find arguments that you either misspelled or did not use in your program. The listing below shows an example.
Listing 31-25. Warning about unused function arguments
void func(int temp, int error);
{
error = do_something(); /* WARNING: temp is unused. */
}
To prevent this warning, you can declare an argument in a few ways:
• Use the pragma unused
, as shown in the listing below.
Listing 31-26. Using pragma unused() to prevent unused argument messages
void func(int temp, int error)
{
#pragma unused (temp)
/* Compiler does not warn that temp is not used. */
error=do_something();
}
• Do not give the unused argument a name. The listing below shows an example.
The compiler allows this feature in C++ source code. To allow this feature in C source code, disable ANSI strict checking.
Listing 31-27. Unused, Unnamed Arguments
void func(int /* temp */, int error)
{
/* Compiler does not warn that "temp" is not used. */
error=do_something();
}
This pragma corresponds to the Unused Arguments setting in the C/C++ Warnings
Panel . By default, this pragma is off
.
31.35 warn_unusedvar
Controls the recognition of unreferenced variables.
Syntax
#pragma warn_unusedvar on | off | reset
Remarks
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
487
warn_unusedvar
If you enable this pragma, the compiler issues a warning message when it encounters a variable you declare but do not use.
This check helps you find variables that you either misspelled or did not use in your program.
shows an example.
Listing 31-28. Unused Local Variables Example
int error; void func(void)
{
int temp, errer; /* NOTE: errer is misspelled. */
error = do_something(); /* WARNING: temp and errer are unused. */
}
If you want to use this warning but need to declare a variable that you do not use, include the pragma unused
, as in
.
Listing 31-29. Suppressing Unused Variable Warnings
void func(void)
{
int i, temp, error;
#pragma unused (i, temp) /* Do not warn that i and temp */
error = do_something(); /* are not used */
}
By default, this pragma is off.
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
488 Freescale Semiconductor, Inc.
Pobierz
Reklama