【MISRA C 2012】Rule 2.6 函数不应该包含未使用的标签声明

1. 规则

1.1 原文

Rule 2.6 A function should not contain unused label declarations
Category Advisory
Analysis Decidable, Single Translation Unit
Applies to C90, C99

1.2 分类

规则2.6:函数不应该包含未使用的标签声明
Advisory建议类规范。

2. 关键描述

如果声明了一个标签但没有使用,那么审阅者就不清楚这个标签是多余的还是错误地没有使用。

3. 代码实例

例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*/
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yy九歌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值