← Back to team overview

t-kernel-zh team mailing list archive

[open t-kernel] 在ARMCC中如何将警告当错误处理(ARM RVCT,KEIL)

 

在修理代码中的警告的时候,把警告当作错误对待,然后停止编译,这个在修
理过程序中比较有用。查阅 KEIL 的说明文档:

C:\Keil_v522\ARM\Hlp\DUI0375G_02_mdk_armcc_user_guide.pdf:7-316

> 7.43 --diag_error=tag[,tag,...]
> Sets diagnostic messages that have a specific tag to Error severity.
> Note
> This option has the #pragma equivalent #pragma diag_error.
> Syntax
> --diag_error=tag[,tag,…]
> Where tag can be:
> • A diagnostic message number to set to error severity. This is the four-digit number, nnnn, with the
> tool letter prefix, but without the letter suffix indicating the severity.
> • warning, to treat all warnings as errors.
> Usage
> The severity of the following types of diagnostic messages can be changed:
> • Messages with the number format #nnnn-D.
> • Warning messages with the number format CnnnnW

根据文档所述,可以在编译选项中添加

CFLAGS += --diag_error=warning

即可在遇到警告时停止编译,然后进行代码的修改。

与此相关的一个常用的选项是,禁止某个警告:

C:\Keil_v522\ARM\Hlp\DUI0375G_02_mdk_armcc_user_guide.pdf:7-319

> 7.46 --diag_suppress=tag[,tag,...]
> Suppresses diagnostic messages that have a specific tag.
> Behaves analogously to --diag_error, except that the compiler suppresses the diagnostic messages
> having the specified tags rather than setting them to have Error severity.
> Note
> This option has the #pragma equivalent #pragma diag_suppress.
> Syntax
> --diag_suppress=tag[,tag,…]
> Where tag can be:
> • A diagnostic message number to be suppressed. This is the four-digit number, nnnn, with the tool
> letter prefix, but without the letter suffix indicating the severity.
> • error, to suppress all errors that can be downgraded.
> • warning, to suppress all warnings.

例如禁止下面这个警告,警告提示一般有个 #nnnn-D,其中nnnn就是这个警告
对应的号码。
> "driver/console/console_drv.c", line 735: Warning:  #1293-D: assignment in condition                                                                                                                                                                            
>                 if (!(old = check_port(port))) return -1;                                                                                                                                                                                                       
>                      ^ 

通过编译选项中添加

CFLAGS += --diag_suppress=735

下次编译将不会出现警告。


-- 

duhuanpeng.
u74147@xxxxxxxxx