user3048782
user3048782

Reputation: 61

Why do I get "Invalid conversion from "void *" to "int**" error?

my code shows this warnings when compiling with "g++ -Wall -pedantic -Wno-long-long -c main.c". I have to compile in this mode, becouse its a homework and we have an application that corrects them and it uses this compile mode.

  1. Error: invalid conversion from "void" to "int** " [-fpermissive]
  2. Error: invalid conversion from "void" to "int* " [-fpermissive]
  3. Error: invalid conversion from "void" to "main(int, char*)::VYSLEDEK" [-fpermissive]

the same errors continue as i realloc quite a lot in my program. I tried to change almost everything in that realloc, it is still the same.

Parts of the code :

    struct VYSLEDEK
{
    int sirka;
    int vyska;
    int zacatek_x;
    int zacatek_y;
    int soucet;
} *vysledek;
    int **matice,**soucty;

    .....       

    matice=(int**)malloc(1*sizeof(int*));
    matice[0]=(int*)malloc(1*sizeof(int));
    soucty=(int**)malloc(1*sizeof(int*));
    soucty[0]=(int*)malloc(1*sizeof(int));

    .....

1.      matice=realloc(matice,naalokovano*2*sizeof(int*));
2.      soucty=realloc(soucty,naalokovano*2*sizeof(int*));

    .....

        for (i=0;i<(naalokovano*2);i++)
        {
3.            matice[i]=realloc(matice[i],sizeof(int));
4.            soucty[i]=realloc(soucty[i],sizeof(int*));
        };

    .....

5.      vysledek=realloc(vysledek,vysledku*sizeof(struct VYSLEDEK*));

Thank you for your help.

Upvotes: 3

Views: 11551

Answers (1)

Christopher Creutzig
Christopher Creutzig

Reputation: 8774

You already did cast the result of malloc to the right type. Do the same for the realloc calls, too.

BTW: Don’t complain that they force you to switch on the warnings. I think it’s the most sensible thing to do by default, I always use at least -Wall -Werror.

Upvotes: 3

Related Questions