I'm trying to pass a whole structure through a function by value, and I test if the pass was successful by displaying the variables in the structure that was passed.
When I compile and run the program, the variables display correctly, but I get a warning:
warning: parameter names (without types) in function declaration
So it refers to the function prototype being declared with parameter names that had no types? But if I declared the function correctly, why am I getting this warning?
Also, in the short program I wrote to test this, the warning doesn't affect the fact that the output being displayed is correct.
But if I were to get this warning under the same circumstances (passing struct through function) when writing a larger-scale program, will it affect the output in that program being correct?
My code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void pass(Info);
typedef struct {
char str[10];
int num;
} Info;
void main() {
Info i;
strcpy(i.str, "Hello!");
i.num = 1;
pass(i);
}
void pass(Info i) {
printf("%s\n", i.str);
printf("%d\n", i.num);
}
Output:
Hello!
1
You have the typedef
statement after the usage of the newly defined type (synonym for another type, to be nitpicky). At that point, in the function forward declaration, compiler does not know a type named Info
. So, it assumes it to be a variable name.
Move the typedef
before function prototype.
That said, void main()
is not a valid signature for main()
in a hosted environment. It should be int main(void)
, at least.