Type cast erorr - from 'void *' to 'int (*)[3]'

Discussion in 'C++' started by Hiusing Ngai, Oct 14, 2003.

  1. Hiusing Ngai

    Hiusing Ngai Guest

    Hello,

    I'm porting some C code to VC++ 7. A line of C code is:
    int (*v[7])[3];

    and the C code allocate memory:
    v[6] = calloc (width*5, sizeof **v);

    The VC++ 7 has the following erorr when I compile the program.
    error C2440: '=' : cannot convert from 'void *' to 'int (*)[3]'

    Do you have any idea how to type cast it?
    I tried (int**) but didn't work.

    Thanks,
    Hiusing
     
    Hiusing Ngai, Oct 14, 2003
    #1
    1. Advertising

  2. Hiusing Ngai

    Rolf Magnus Guest

    Hiusing Ngai wrote:

    > Hello,
    >
    > I'm porting some C code to VC++ 7.


    If it's C code, why don't you compile it with a C compiler?

    > A line of C code is:
    > > int (*v[7])[3];

    >
    > and the C code allocate memory:
    > v[6] = calloc (width*5, sizeof **v);
    >
    > The VC++ 7 has the following erorr when I compile the program.
    > error C2440: '=' : cannot convert from 'void *' to 'int (*)[3]'
    >
    > Do you have any idea how to type cast it?
    > I tried (int**) but didn't work.


    Uhm, did you also try (int (*)[3]), like the compiler said? v[6] is of
    type pointer to array [3] of int, not of type pointer to pointer to
    int.
    Anyway, could you explain why you need an array of pointers to arrays of
    int? Sounds overly complex to me.
     
    Rolf Magnus, Oct 15, 2003
    #2
    1. Advertising

  3. Hiusing Ngai

    David White Guest

    Hiusing Ngai <> wrote in message
    news:...
    > Hello,
    >
    > I'm porting some C code to VC++ 7. A line of C code is:
    > int (*v[7])[3];
    >
    > and the C code allocate memory:
    > v[6] = calloc (width*5, sizeof **v);
    >
    > The VC++ 7 has the following erorr when I compile the program.
    > error C2440: '=' : cannot convert from 'void *' to 'int (*)[3]'
    >
    > Do you have any idea how to type cast it?


    v[6] = static_cast<int (*)[3]>(calloc (width*5, sizeof **v));

    > I tried (int**) but didn't work.


    That's because int** isn't int (*)[3].

    DW
     
    David White, Oct 15, 2003
    #3
  4. Hiusing Ngai

    Ron Natalie Guest

    "Hiusing Ngai" <> wrote in message news:...
    );
    >
    > The VC++ 7 has the following erorr when I compile the program.
    > error C2440: '=' : cannot convert from 'void *' to 'int (*)[3]'
    >
    > Do you have any idea how to type cast it?
    > I tried (int**) but didn't work.


    The cast is (int (*)[3])

    Of course, if you would use new rather than calloc, you'd not have
    to cast.

    int** is NOT compatible with int (*)[n]
     
    Ron Natalie, Oct 15, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    606
    Jack Klein
    Apr 22, 2005
  2. Schnoffos
    Replies:
    2
    Views:
    1,260
    Martien Verbruggen
    Jun 27, 2003
  3. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    843
    The Real OS/2 Guy
    Oct 28, 2003
  4. Replies:
    5
    Views:
    886
    S.Tobias
    Jul 22, 2005
  5. Abhishek
    Replies:
    12
    Views:
    843
    Eric Sosman
    Jan 30, 2006
Loading...

Share This Page