Rule 2.6 A function should not contain unused label declarations
Category Advisory
Analysis Decidable, Single Translation Unit
Applies to C90, C99
规则2.6:函数不应该包含未使用的标签声明
Advisory建议类规范。
如果声明了一个标签但没有使用,那么审阅者就不清楚这个标签是多余的还是错误地没有使用。
例1,规范中例程:
其中,label1是没有使用到的函数块,是不允许的。
void unused_label ( void )
{
int16_t x = 6;
label1: /* 代码中没有使用,不合规的 */
use_int16 ( x );
}
例2,使用397 MCAL测试工程中的为例,如下代码中Adc_SWGroupDemo是没有被使用到的接口,如果ADC使用中断周期处理,Adc_SWGroupDemo应该删除,属于没有被使用到的定义
/******************************************************************************
** Syntax : void Adc_SWGroupDemo(void) **
** **
** Service ID: : NA **
** **
** Sync/Async: : Synchronous **
** **
** Reentrancy: : Non Reentrant **
** **
** Parameters (in): none **
** **
** Parameters (out): none **
** **
** Return value : none **
** **
** Timing : Fixed Cyclic/Variable Cyclic **
** **
** Description : This routine will start the SW Group Configured as: **
** Conversion mode : Continuous **
** Result Access mode : Streaming, Linear **
** Streaming Length : 5 **
** Channels in a groups: AN1, AN0 **
** Result buffer : ADC_SW_GRP_RES[5][2] **
** Conversion is stopped automatically when once configured **
** number of samples are captured **
** Read and print the latest conversion result using pointer **
** returned from API Adc_GetStreamLastPointer **
******************************************************************************/
void Adc_SWGroupDemo(void)
{
static uint8 grpNum = 0;
static uint16 adc_delay_time_us;
adc_delay_time_us = 0;
do{
//BspStm_waitTime(1);
delay_ms(1);
adc_delay_time_us++;
}while((g_stAdcCfg.AdcConvertflag[grpNum] == ADC_Convert_Busy) && (adc_delay_time_us<100));
Adc_StartGroupConversion(g_grpIndex[0]);
Adc_StartGroupConversion(g_grpIndex[1]);
Adc_StartGroupConversion(g_grpIndex[2]);
adc_delay_time_us = 0;
do{
//BspStm_waitTime(1);
delay_ms(1);
adc_delay_time_us++;
}while((g_stAdcCfg.AdcConvertflag[grpNum] == ADC_Convert_Busy) && (adc_delay_time_us<100));
uint8 i;
for (i = 0; i < 3; i++) {
fVoltage[grpNum][i] = G0_ResultPtr[grpNum][i] * 3.3f / 4096;
}
grpNum++;
if (grpNum > 2) {
grpNum = 0;
}
} /* Adc_SWGroupDemo */
/*******************************************************************************
** Syntax : void DemoApp_Adc_Init(void) **
** **
** Service ID: : NA **
** **
** Sync/Async: : Synchronous **
** **
** Reentrancy: : Reentrant **
** **
** Parameters (in): none **
** **
** Parameters (out): none **
** **
** Return value: none **
** **
** Description : Initialize ADC module **
*******************************************************************************/
void DemoApp_Adc_Init(void)
{
SRC_VADCG2SR0.U |= SRE_ENABLE;
// SRC_VADCG8SR0.U |= SRE_ENABLE;
const Adc_ConfigType * ConfigPtr = NULL_PTR;
ConfigPtr = &Adc_Config;
Adc_Init(ConfigPtr);
Adc_TriggerStartupCal();
/* Wait till the StartUp calibration is over */
while(Adc_GetStartupCalStatus() != ADC_STARTUP_CALIB_OVER) {}
/* Initialize ADC interrupt */
IrqAdc_Init();
SRC_VADC_G2_SR0.B.SRE = 1U;
SRC_VADC_G2_SR1.B.SRE = 1U;
SRC_VADC_G2_SR2.B.SRE = 1U;
SRC_VADC_G2_SR3.B.SRE = 1U;
SRC_VADC_G3_SR0.B.SRE = 1U;
SRC_VADC_G8_SR0.B.SRE = 1U;
Std_ReturnType lRetVal;
lRetVal = Adc_SetupResultBuffer(g_grpIndex[0], G0_ResultPtr[0]);
if(lRetVal != E_NOT_OK) {
Adc_EnableGroupNotification(g_grpIndex[0]);
Adc_StartGroupConversion(g_grpIndex[0]);
} else {
/*Could not setup result buffer*/
}
lRetVal = Adc_SetupResultBuffer(g_grpIndex[1], G0_ResultPtr[1]);
if(lRetVal != E_NOT_OK) {
Adc_EnableGroupNotification(g_grpIndex[1]);
Adc_StartGroupConversion(g_grpIndex[1]);
} else {
/*Could not setup result buffer*/
}
lRetVal = Adc_SetupResultBuffer(g_grpIndex[2], G0_ResultPtr[2]);
if(lRetVal != E_NOT_OK) {
Adc_EnableGroupNotification(g_grpIndex[2]);
Adc_StartGroupConversion(g_grpIndex[2]);
} else {
/*Could not setup result buffer*/
}
}