This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Function with different types of arguments

Hello!
In the program, I decided to redo some of the functions and added the structure:

typedef struct
{
  GPIO_TypeDef * GPIOx;
  uint16_t PINx;
}GPIO_PINdef;

Previously, the function looked like this: void GPIO_InitPIN(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin_x)

Now it looks like this: void GPIO_InitPIN(GPIO_PINdef GPIOx)

So here is the question, calling a new function now works both in the old and new way, i.e. to call a function in this form: GPIO_InitPIN(GPIOB, GPIO_Pin_8)

and in this form: 

GPIO_PINdef SPI_CS;
GPIO_InitPIN(SPI_CS);
the compiler does not swear and the program runs correctly.

But everything was fine until I started getting rid of "warning" during compilation, namely "function" GPIO_InitPIN "declared implicitly".
I copy the function description into the header file and after that everything stops working:
void GPIO_InitPIN (GPIO_PINdef x); - adding this description in header file, swears that there are too many arguments when calling this function GPIO_InitPIN(GPIOB, GPIO_Pin_8)

How can this function be written in the header file to get rid of "warning"?

Parents
  • The mystery here is not that the code fails now, after you added the required declaration.  The mystery is that it worked before.  The code, as-is, is just blatantly wrong.  Calling a function with a different sequence of arguments than the one it actually has generally causes undefined behaviour.

    Changing the header file is not the way to fix this.  The declaration in the header has to match the actual implementation of the function.  What you have to fix are the invocations.

Reply
  • The mystery here is not that the code fails now, after you added the required declaration.  The mystery is that it worked before.  The code, as-is, is just blatantly wrong.  Calling a function with a different sequence of arguments than the one it actually has generally causes undefined behaviour.

    Changing the header file is not the way to fix this.  The declaration in the header has to match the actual implementation of the function.  What you have to fix are the invocations.

Children