vertex* conversion in c++

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
w.kosma
Posts: 19
Joined: Fri Oct 28, 2005 11:33 pm

vertex* conversion in c++

Post by w.kosma »

hello,

i`m new here and to pspdev,
i was playing with some source code,
i wanted to mix some examples, one of which in c another in c++,

i get only one error about invalid conversion
from this line (taken from c example):

struct Vertex* vertices = sceGuGetMemory((NUM_VERTICES+1) * sizeof(struct Vertex));

any ideas how to do it in c++

i would be very grateful for any help,

thanks,
wojciech
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

The compiler is just warning you (forcefully) that you are taking a pointer to an anonymous block of memory and using it as a specific type. Just use a "cast" to tell the compiler that you know what you are doing:

struct Vertex* vertices = (struct Vertex*)sceGuGetMemory((NUM_VERTICES+1) * sizeof(struct Vertex));

Hope this helps!
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

sceGuGetMemory() returns type void *. You're assigning it to type struct Vertex *.

In C, all pointer types are compatible with void *, so you can just make the assignment.

In C++ the cast is mandatory, as Dr.Vegetable has shown.

One very common place this happens is when C++ programs use malloc, which also returns void *.

Jim
Post Reply