forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

vertex* conversion in c++

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
w.kosma



Joined: 28 Oct 2005
Posts: 19

PostPosted: Sun Dec 18, 2005 12:56 am    Post subject: vertex* conversion in c++ Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Sun Dec 18, 2005 1:28 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Dec 18, 2005 8:04 am    Post subject: Reply with quote

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
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group