1

I have 3 file dependencies, in one of them I have implemented one function that you can see the first of all below. It returns an int type of 32 bits. The second file implements a function that calls the funtion of the first file. This function will be called from main file (third file). When I compile (with keil IDE) all the files I have the following warning msg:

compiling App_Task_CAN.c...
..\src\Application_Tasks\App_Task_CAN.h(132): warning:  #1295-D: Deprecated      declaration App_Task_CAN_GetError - give arg types
  uint32_t App_Task_CAN_GetError();

This is a part of code in a file I have included stm32l4xx_hal_can.c:

 uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan)
 {
      return hcan->ErrorCode;
 }

where hcan is in stm32l4xx_hal_can.h a type of:

   /**
   * @brief  CAN handle Structure definition
   */
 typedef struct
 {
     CAN_TypeDef                 *Instance;  /*!< Register base address          */

     CAN_InitTypeDef             Init;       /*!< CAN required parameters        */

     CanTxMsgTypeDef*            pTxMsg;     /*!< Pointer to transmit structure  */

     CanRxMsgTypeDef*            pRxMsg;     /*!< Pointer to reception structure */

     __IO HAL_CAN_StateTypeDef   State;      /*!< CAN communication state        */

     HAL_LockTypeDef             Lock;       /*!< CAN locking object             */

     __IO uint32_t               ErrorCode;  /*!< CAN Error code                 */ 

}CAN_HandleTypeDef;

Furthermore I have this implementation in other file calling to the first shown function in App_Task_CAN.c :

...
CAN_HandleTypeDef HCAN_Struct;//hcan struct type declaration in this file

uint32_t App_Task_CAN_GetError()
{   
    static uint32_t ErrorNumb;

    ErrorNumb=HAL_CAN_GetError(&HCAN_Struct);

    return ErrorNumb; //I want this functions returns an int value.
}

Main code in main.c:

int main(void)
{
    uint32_t    ErrorType=0;

    while (1)
    {
        ErrorType=App_Task_CAN_GetError(); //it takes the resulting value of calling HAL_CAN_GetError(&HCAN_Struct)
    }
}

The warning disappears when I pass an argument. But I don't know why it is asking me for a argument for saving the return value.

Why does it needs an argument since it returns an uint32_t? Is it possible to improve the code in order to get updated ErrorType from main when main calls App_Task_CAN_GetError()?

Note: stm32l4xx_hal_can.c and .h can not been modified since they are system libraries files.

Suvi_Eu
  • 255
  • 1
  • 3
  • 16
  • 2
    `uint32_t App_Task_CAN_GetError()` --> `uint32_t App_Task_CAN_GetError(void)` – LPs Mar 17 '17 at 08:52
  • [why-does-a-function-with-no-parameters-compared-to-the-actual-function-definiti](http://stackoverflow.com/questions/13950642/why-does-a-function-with-no-parameters-compared-to-the-actual-function-definiti) – LPs Mar 17 '17 at 08:54
  • @LPs warning disappears and it works correctly. Thanks. – Suvi_Eu Mar 17 '17 at 10:04

1 Answers1

9

Using , the declaration

int foo(void) 

means a function returning int that takes no parameters. The declaration

int f() 

means a function returning int that takes any number of parameters.

Thus, if you have a function that takes no parameters in , the former is the correct prototype.

LPs
  • 16,045
  • 8
  • 30
  • 61
  • 2
    Also note that the compiler was correct to warn about this feature being deprecated, as per 6.11.6 Function declarators "The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature." – Lundin Mar 20 '17 at 12:49