Warning for incompatible pointer type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,
In the function bellow I pass two const pointers to a function. One
pointer to a char** and the other to char*. When I compiling the
program via gcc test.c -o test I obtain a warning:

test.c:18:5: warning: passing argument 1 of ‘foo’ from incompatible pointer type
test.c:4:6: note: expected ‘const char **’ but argument is of type ‘char **’

What is the reason for the warning? I won't change the char** argument
in the function so I think that declare it as const is correct. What
the argument const char* do no emits a warning? I tested the program
with gcc 4.5.2 and 4.6.0 and I obtain the warning in each compiler.

Thanks

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void foo(const char** array,const char* array1,const size_t n)
{
    size_t i=0;
    for(i=0;i<n;i++)
    {
        strlen(array[i]);
        strlen(array1);
    }
    return;
}
int main()
{
    char** array=NULL;
    char* array1=NULL;
    size_t n=0;
    foo(array,array1,n);
    return 0;
}

-- 
*****************************************
José Luis García Pallero
jgpallero@xxxxxxxxx
(o<
/ / \
V_/_
Use Debian GNU/Linux and enjoy!
*****************************************



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux