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

H

Hiusing Ngai

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
 
R

Rolf Magnus

Hiusing said:
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.
 
D

David White

Hiusing Ngai said:
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 said:
I tried (int**) but didn't work.

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

DW
 
R

Ron Natalie

Hiusing Ngai said:
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]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top