incompatible pointer types passing short * to short *(*)[ ]

Related searches

Certainly, I did something wrong here, but looking at this I can't figure out why I am receiving these warnings:

warning: incompatible pointer types passing '__int16_t *' (aka 'short *') to parameter of type '__int16_t *(*)[4]' [-Wincompatible-pointer-types]
        hammingDistance2d(ptr0, ptr1);

in my small code segment:

void hammingDistance2d(__int16_t *src0[N][N],
                       __int16_t *src1[N][N]){
    int i, j;
    __uint16_t Hdis[N][N] = {0};

    for (i=0 ; i<N; i++){
        for (j=0; j<N; j++){
            __uint16_t z = *src0[i][j] ^ *src1[i][j];
            while (z > 0)
            {
                Hdis[i][j] += z & 1;
                z >>= 1;
            }
        }
    }
int main(){

    __int16_t src0[N][N] = {  { 1, 1, 1, 1},
                              { 2, 2, 2, 2},
                              { 3, 3, 3, 3},
                              { 4, 4, 4, 4} };
    __int16_t src1[N][N] = {  { 1, 1, 1, 1},
                              { 2, 2, 2, 2},
                              { 5, 5, 5, 5}, // different row
                              { 4, 4, 4, 4} };
    __int16_t *ptr0 =  &src0[0][0];
    __int16_t *ptr1 =  &src1[0][0];

    hammingDistance2d(ptr0, ptr1);
    return 0;
}

and I'd like to use keep the use of intermediate pointers to the arrays.

These variables

__int16_t *ptr0 =  &src0[0][0];
__int16_t *ptr1 =  &src1[0][0];

are explicitly declared as having the type __int16_t *.

But the corresponding function parameters

void hammingDistance2d(__int16_t *src0[N][N],
                       __int16_t *src1[N][N]){

in fact has the type __int16_t * ( * )[N].

There is no implicit conversion from the first type to the second. So the compiler issues an error.

It seems what you mean is the following

void hammingDistance2d(__int16_t src0[N][N],
                       __int16_t src1[N][N]){
    int i, j;
    __uint16_t Hdis[N][N] = {0};

    for (i=0 ; i<N; i++){
        for (j=0; j<N; j++){
            __uint16_t z = src0[i][j] ^ src1[i][j];
            while (z > 0)
            {
                Hdis[i][j] += z & 1;
                z >>= 1;
            }
        }
    }
}

And a function call can look like

hammingDistance2d( src0, src1 );

If you want to declare intermediate pointers used as the function arguments then you should write

__int16_t ( *ptr0 )[N] =  src0;
__int16_t ( *ptr1 )[N] =  src1;

and call the function like

hammingDistance2d( ptr0, ptr1 );

incompatible pointer types passing short * to short *(*)[ ], warning: incompatible pointer types passing '__int16_t *' (aka 'short *') to parameter of type '__int16_t *(*)[4]' [-Wincompatible-pointer-types]� I am attempting to implement the "rewrite" method of vertical scaling in pset 4's resize problem. I declare an array of RBTTRIPLE's in which I want to construct the outfile scanlines.

You're passing a 2D array of __int16, but your function is expecting a pointer to __int16_t.

Fix the function definition to work with what you're sending it.

void hammingDistance2d(__int16_t src0[N][N],
                       __int16_t src1[N][N]){
    int i, j;
    __uint16_t Hdis[N][N] = {0};

    for (i=0 ; i<N; i++){
        for (j=0; j<N; j++){
            __uint16_t z = src0[i][j] ^ src1[i][j];
            while (z > 0)
            {
                Hdis[i][j] += z & 1;
                z >>= 1;
            }
        }
    }

And call it as:

hammingDistance2d(src0, src1);

C: Vigenere, The error comes from here: for(int l=0; l<strlen(argv); l++). Think about it. strlen() wants a const char* or char* . You gave it argv , which is an array of the� In effect, this tells the compiler that you know what you are doing and to stop bothering you with warnings about it. Another use is to cast from a pointer-to-derived class to a pointer-to-base class. Another use is to cast away the const-ness of a variable to pass it to a function that requires a non-const argument. Most of these cast

The function is expecting:

__int16_t *src0[N][N]

Which has type (as the compiler suggests) __int16_t *(*)[4], or, in English: pointer to [pointer to [array of 4 __int16_t]] (notice the square brackets I am using for emphasis).

What you have here:

__int16_t src0[N][N] = {  { 1, 1, 1, 1},
                          { 2, 2, 2, 2},
                          { 3, 3, 3, 3},
                          { 4, 4, 4, 4} };

Is of type __int16_t (*)[4], that is: pointer to [array of 4 __int16_t].

You probably meant to declare:

hammingDistance2d(__int16_t src0[N][N], __int16_t src1[N][N]) {
    // ...
}

Which is the same as:

hammingDistance2d(__int16_t (*src0)[N], __int16_t (*src1)[N]) {
    // ...
}

Note that in such case you don't have to dereference src0[i][j] using the * operator.

I keep getting an error: incompatible pointer types passing 'string , In short, the shift function as written can't make up its mind what it wants to do! A rewrite is in order. Do you want to convert a single char or all� SET.c:322: warning: passing arg 1 of `Set_Union' from incompatible pointer type SET.c:322: warning: passing arg 2 of `Set_Union' from incompatible pointer type SET.c:324: warning: passing arg 1 of `Set_Print' from incompatible pointer type SET.c:329: warning: passing arg 1 of `Set_Intersection' from incompatible pointe r type SET.c:329: warning

Incompatible pointer types, warning: incompatible pointer types assigning to 'uint8_t *' (aka 'unsigned char *') from 'EXTDISPBUF_t *' [-Wincompatible-pointer-types] initials.c:20:18: error: incompatible pointer types passing 'string' (aka 'char *') to parameter of type 'string *' (aka 'char **'); take the address with & [-Werror

Pointer type mismatches for standard C integral types � Issue #7983 , chpl foo.chpl foo.h In file included from /path/to/_main.c:43: /path/to/foo.c:23:8: error: incompatible pointer types passing '_ref_int64_t' (aka 'long� Another example is the "&" operator: &sTest is a pointer to a fixed-sized array and has type "const char[5]*"; Both sTest and &sTest point to the same place, but have different types. Thus assigning sTest works because both pointers are of the same type. Assigning &sTest also works, but since the types are different, it generates a warning.

Re: Passing char-Array Pointer does not work 843829 Oct 30, 2007 9:28 AM ( in response to 843829 ) Ok, I changed it a bit: in Java:

Comments
  • Why are you using __int16_t (which is a system type; the double-underscore prefix is reserved for the implementation) instead of int16_t (which is the usable version of the type name)?
  • *src0[N][N] is a 2D array of pointers, to which you pass the address of one element of a 2D array of integers.
  • Thanks @Vlad. If I wanted to use pointers here, what would have been the correct form then?
  • @Amir Do you mean to use pointers within the function instead of the subscript operator?
  • thanks @Vlad, I guess there was my issue and I thought just like a 1d array for which &src[0] has the starting address, a &src[0][0] must have been having the same thing for a 2d.
  • @Amir The values of addresses can coincide but the types of expressions are different. And you may not to apply two subscript operators to a pointer of the type __int16_t *