Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Type cast erorr - from 'void *' to 'int (*)[3]'

Reply
Thread Tools

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

 
 
Hiusing Ngai
Guest
Posts: n/a
 
      10-14-2003
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


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      10-14-2003
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.

 
Reply With Quote
 
 
 
 
David White
Guest
Posts: n/a
 
      10-14-2003
Hiusing Ngai <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Ron Natalie
Guest
Posts: n/a
 
      10-15-2003

"Hiusing Ngai" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
);
>
> 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]


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I solve this erorr usr/lib/python2.6 : permisson denied Mohseniaref Python 3 08-03-2010 12:16 PM
Unknown Erorr Atlas framework TARUN ASP .Net 1 09-12-2006 01:57 PM
Cast from type 'DBNull' to type 'String' is not valid. Elmo Watson ASP .Net 3 12-25-2003 03:30 AM
Difference betn: errorPage directive and <erorr-page> in web.xml may Java 1 09-29-2003 10:47 AM
cast from datetime type to smalldatetime type? Salim Af■ar ASP .Net 1 08-01-2003 02:01 PM



Advertisments