0

I have found something like

(void)thread_id;

in CMSIS-RTOS API.

Here is whole function:

/**
* @brief Create and Initialize a Message Queue
* @param queue_def     queue definition referenced with \ref osMessageQ.
* @param  thread_id     thread ID (obtained by \ref osThreadCreate or \ref osThreadGetId) or NULL.
* @retval  message queue ID for reference by other functions or NULL in case of error.
* @note   MUST REMAIN UNCHANGED: \b osMessageCreate shall be consistent in every CMSIS-RTOS.
*/
osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId thread_id)
{
  (void) thread_id;
  
#if( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 )

  if ((queue_def->buffer != NULL) && (queue_def->controlblock != NULL)) {
    return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock);
  }
  else {
    return xQueueCreate(queue_def->queue_sz, queue_def->item_sz);
  }
#elif ( configSUPPORT_STATIC_ALLOCATION == 1 )
  return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock);
#else  
  return xQueueCreate(queue_def->queue_sz, queue_def->item_sz);
#endif
}

thread_id as you see is unused parameter.

Is (void)thread_id; line actually does something (compiler, warnings etc.), or this is just "information for humans" that this is not used parameter?

Kamil
  • 13,363
  • 24
  • 88
  • 183
  • 2
    It is a no-op which silences the compiler warning "Unused variable." It also shows the human reader that this is intentional. – Weather Vane Feb 13 '22 at 23:14
  • Thank you @WeatherVane. Do these expressions have a name by which to find them in the compiler documentation or language specification? I don't know where to start looking. – Kamil Feb 13 '22 at 23:18
  • 1
    I don't know the name of the technique, but have linked to a duplicate. – Weather Vane Feb 13 '22 at 23:22

0 Answers0