static关键字 weak关键字

1、static关键字

static HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
{
  ...
}

在函数前面加了一个static关键字,则该工程的其他文件中不能调用此函数,此函数只能在本文件中被调用。

 

static关键字 weak关键字_第1张图片

 

 

 

 

 

 

 

 

2、weak关键字

/**
  * @brief  Rx Transfer completed callbacks.
  * @param  huart  Pointer to a UART_HandleTypeDef structure that contains
  *                the configuration information for the specified UART module.
  * @retval None
  */
__weak void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
  /* Prevent unused argument(s) compilation warning */
  UNUSED(huart);
  /* NOTE: This function should not be modified, when the callback is needed,
           the HAL_UART_RxCpltCallback could be implemented in the user file
   */
}

1)这是串口接收中断的一个钩子函数,可以看出这个函数并没有执行什么实质性操作,而只是为了语法不报错。

2)此时用户可以在用户文件中重新定义HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)函数,编译时不会报重定义错误

3)程序在运行的过程中执行的是用户定义的函数。

 

你可能感兴趣的:(static关键字 weak关键字)