MDK-ARMarmcc编译器——用pragma编译命令禁止诊断信息输出的方法

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

MDK-ARMarmcc编译器——用pragma编译命令禁止诊断
信息输出的方法
Controlling compiler diagnostic messages with pragmas
5.3 Controlling compiler diagnostic messages with pragmas
Pragmas let you suppress, enable, or change the severity of specific diagnostic messages from within your code.
For example, you can suppress a particular diagnostic message when compiling one specific function.
Note
You can also use options to suppress or change the severity of messages, but the change applies for the entire compilation.
Diagnostic messages use the pragma state in place at the time they are generated. If you use pragmas to control a message in your code, you must be aware of when that message is generated. For example, the following code is intended to suppress the diagnostic message 177 (“Function was declared but never referenced”) for the dummy function:
#include
#pragma push
#pragma diag_suppress 177
static int dummy(void)
{
printf("This function is never called.");
return 1;
}
#pragma pop
main(void){
printf("Hello world!\n");
}
The intention of the programmer is to push the current pragma state to the stack, suppress diagnostic message 177 when compiling the dummy function, then restore the original pragma state before continuing with compilation.
However, message 177 is only generated after all functions have been processed. Therefore, the message is generated after pragma pop restores the pragma state, and message 177 is not suppressed.
Removing pragma push and pragma pop would correctly suppress message 177, but would suppress messages for all unreferenced functions rather than just the dummy function. Related concepts
5.2 Options that change the severity of compiler diagnostic messages
5.4 Prefix letters in compiler diagnostic messages
5.5 Compiler exit status codes and termination messages
5.6 Compiler data flow warnings
Related reference
5.1 Severity of compiler diagnostic messages
9.75 #pragma diag_default tag[,tag,...]
9.76 #pragma diag_error tag[,tag,...]
9.77 #pragma diag_remark tag[,tag,...]
9.78 #pragma diag_suppress tag[,tag,...]
9.79 #pragma diag_warning tag[, tag, ...]
9.92 #pragma pop
9.93 #pragma push
7.41 --diag_error=tag[,tag,...]
7.42 --diag_remark=tag[,tag,...]
7.43 --diag_style=arm|ide|gnu compiler option
7.44 --diag_suppress=tag[,tag,...]
7.45 --diag_suppress=optimizations
7.46 --diag_warning=tag[,tag,...]
7.47 --diag_warning=optimizations
Copyright ? Keil, An ARM Company. All rights reserved.
#pragma diag_suppress tag[,tag,...]
9.78 #pragma diag_suppress tag[,tag,...]
This pragma disables all diagnostic messages that have the specified tags.
Diagnostic messages are messages whose message numbers are postfixed by -D , for example, #550-D .
#pragma diag_suppress behaves analogously to #pragma diag_error , except that the compiler suppresses the diagnostic messages having the specified tags rather than setting them to have Error severity.
Syntax
#pragma diag_suppress tag[,tag,...]
Where:
tag[,tag,...]
is a comma-separated list of diagnostic message numbers specifying the messages to be suppressed.
Related reference 7.15 --brief_diagnostics, --no_brief_diagnostics 7.41 --diag_error=tag[,tag,...] 7.42 --diag_remark=tag[,tag,...] 7.43 --diag_style=arm|ide|gnu compiler option 7.44 --diag_suppress=tag[,tag,...] 7.45 --diag_suppress=optimizations 7.46 --diag_warning=tag[,tag,...] 7.167 --wrap_diagnostics, --no_wrap_diagnostics 7.47 --diag_warning=optimizations 7.55 --errors=filename 7.162 -W 9.76 #pragma diag_error tag[,tag,...] 9.77 #pragma diag_remark tag[,tag,...] 7.133 --remarks 5 Compiler Diagnostic Messages Copyright ? Keil, An ARM Company. All rights reserved.
Page 1of 1Compiler User Guide: #pragma diag_suppress tag[,tag,...]
#pragma diag_default tag[,tag,...]
9.75 #pragma diag_default tag[,tag,...] This pragma returns the severity of the diagnostic messages that have the specified tags to the severities that were in effect before any pragmas were issued. Diagnostic messages are messages whose message numbers are postfixed by -D , for example, #550-D .
Syntax
#pragma diag_default tag[,tag,...]
Where:
tag[,tag,...]
is a comma-separated list of diagnostic message numbers specifying the messages whose severities are to be changed.
At least one diagnostic message number must be specified.
Examples
// not #included deliberately
#pragma diag_error 223
void hello(void)
{
printf("Hello ");
}
#pragma diag_default 223
void world(void)
{
printf("world!\n");
}
Compiling this code with the option --diag_warning=223 generates diagnostic messages to report that the function printf() is declared implicitly.
The effect of #pragma diag_default 223 is to return the severity of diagnostic message 223 to Warning severity, as specified by the --diag_warning command-line option.
Related concepts
5.3 Controlling compiler diagnostic messages with pragmas
Related reference
9.76 #pragma diag_error tag[,tag,...]
9.77 #pragma diag_remark tag[,tag,...]
9.78 #pragma diag_suppress tag[,tag,...]
9.79 #pragma diag_warning tag[, tag, ...] 7.46 --diag_warning=tag[,tag,...] Copyright ? Keil, An ARM Company. All rights reserved.
Page 1of 1Compiler User Guide: #pragma diag_default tag[,tag,...]。

相关文档
最新文档