I am getting the following warning:
warning: incompatible pointer types passing 'char ()' to parameter of type 'char ()[5]' [-Wincompatible-pointer-types] printField(field[5]);
The printField function looks like this:
void printField(char (*field)[5])
{
...
}
and the field I am giving to it is defined as follows:
char (*field) = get_field(input);
Here is the function call:
printField(field);
Now, I do understand, that there is obviously some sort of mismatch happening, but I can't tell what to change for it not to be there anymore. I would appreciate it very much, if someone could help me.
Assuming that
get_fieldreturn a pointer to the first element (character) of an array (null-terminated string), then that happens to be the same as the pointer to the array itself.If we illustrate it with a simple array:
Then that will look something like this in memory (with pointers added):
Now as can be seen that there are two pointers pointing to the same location:
&a[0]and&s.&s[0]is what using the array decay to, and it's the typechar *.&sis a pointer to the array itself, and have the typechar (*)[5].When we apply it to your case,
fieldis the first pointer, it points to the first element of an array. Which happens to be the same location as the pointer to the array itself which is whatprintFieldexpects.That's the reason it "works". But you should not do like that, you should fix the function to take an
char *argument instead: