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

CODE for Call void function with parameter?

void PWM_Config(uint8_t TIM_PERIOD, uint8_t TIM_PULSE)
{
.
.
.
}

int main()
{

PWM_Config();   // THIS LINE SHOWS AN ERROR

.
.
.
}

ERROR LIST:

main.c(251): error: #165: too few arguments in function call PWM_Config();

BUT, If I write the program below, there is an no error

void PWM_Config()
{
.
.
.
}

int main()
{

PWM_Config();   // NO ERROR

.
.
.
}

KINDLY HELP!

Parents
  • Is this some kind of joke?

    You find it strange if the compiler isn't happy when you tell it
    "This function takes x parameters - and they are of type 1, type 2, type 3, ... - but I prefer to call it with a completely different list of parameters/types?"

    If you write the code for PWM_Config(), then you set the rules for the parameters it should take - and then you need to follow these rules.

    If PWM_Config() is written by someone else, then you have to follow the rules that "someone else" did set up when designing the function.

    If you buy a car with the steering wheel to the right, you just can't get in on the left side and expect to drive the car - you need to adapt to the situation.

    Next thing to realize here is that a function prototype with () in C is a function prototype that doesn't tell what parameters it takes while in C++ it's a function prototype for a function that takes exactly zero parameters. In C, you are expected to write:

    int my_function_that_takes_zero_parameters(void);
    


    to explain that there exists a function - and that the function most definitely do not take any parameters.

Reply
  • Is this some kind of joke?

    You find it strange if the compiler isn't happy when you tell it
    "This function takes x parameters - and they are of type 1, type 2, type 3, ... - but I prefer to call it with a completely different list of parameters/types?"

    If you write the code for PWM_Config(), then you set the rules for the parameters it should take - and then you need to follow these rules.

    If PWM_Config() is written by someone else, then you have to follow the rules that "someone else" did set up when designing the function.

    If you buy a car with the steering wheel to the right, you just can't get in on the left side and expect to drive the car - you need to adapt to the situation.

    Next thing to realize here is that a function prototype with () in C is a function prototype that doesn't tell what parameters it takes while in C++ it's a function prototype for a function that takes exactly zero parameters. In C, you are expected to write:

    int my_function_that_takes_zero_parameters(void);
    


    to explain that there exists a function - and that the function most definitely do not take any parameters.

Children