'Argument type 'void' is incomplete
I'm trying to code this relatively simple code in which I want to be able to change the value of set_current. The error message: "Argument type 'void' is incomplete" keeps showing up and I'm not sure why.
I am not an experienced coder but I have to solve this problem for work. I really hope you can help me.
void setCurrent(float set_current);
int main () {
printf("%i", setCurrent(0));
printf("/n/r");
}
void setCurrent(float set_current){
float v_set_cur = 1.25 + (ILIM_K_USE*set_current);
"Argument type 'void' is incomplete" shows up on the printf line. When I remove the 0 then it works but I want to be able to change that number. What am I missing here?
Solution 1:[1]
You've declared setCurrent as returning void (i.e., nothing), yet in printf("%i", setCurrent(0)); you're expecting it to return an int. One of those things needs to be changed.
Solution 2:[2]
What am I missing here?
You are missing that the function setCurrent needs to return a value that you can print. In other words - the function definition shall not be void.
My guess is that you want:
float setCurrent(float set_current); // Notice float instead of void
int main () {
printf("%f", setCurrent(0)); // Notice %f instead of %i
printf("/n/r");
}
float setCurrent(float set_current){ // Notice float instead of void
float v_set_cur = 1.25 + (ILIM_K_USE*set_current); // Calculate value
return v_set_cur ; // Return the value
}
Solution 3:[3]
When you call setCurrent, nothing is being returned. A void function inherently does not return a value. Based on your printf statement, you are expecting an integer from calling setCurrent. It appears you want to return a float because v_set_curr is a float.
float setCurrent(float set_current);
int main () {
printf("%f", setCurrent(0));
printf("/n/r");
}
float setCurrent(float set_current){
float v_set_cur = 1.25 + (ILIM_K_USE*set_current);
return v_set_cur;
}
Solution 4:[4]
void return type does not return any value; so print operation you should do inside setCurrent function.
Try this code
void setCurrent(float set_current);
int main () {
setCurrent(0);
printf("/n/r");
}
void setCurrent(float set_current){
float v_set_cur = 1.25 + (ILIM_K_USE*set_current);
printf("%.2f", v_set_cur);
}
Solution 5:[5]
I experienced the same problem. But THE SOLUTION is that whenever you want to declare a function with void as output, it is better to use only void as input rather than any other data type.
void is not a complete data type. Because a data type gives the form to which variable is to be stored. But void means nothing. Its like when you have no form to which variable to be stored to return a value than how can you expect a function to return a value...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jwodder |
| Solution 2 | Support Ukraine |
| Solution 3 | |
| Solution 4 | Rajeev Srivastava |
| Solution 5 | halfer |
