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 

Question of function return value

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



Joined: 19 Apr 2007
Posts: 18

PostPosted: Fri Apr 20, 2007 5:53 pm    Post subject: Question of function return value Reply with quote

Hi, I am reading ModuleTurorialv1.pdf, and testing it's code on my psp develop platform.

I am a unix C programmer, and I have never developed on portable device such as PDA or PSP, Now I am confused with a function's C code in this PDF document.

-------------------- code fragement start here ------------
const char*
sv_check_permissions (int client)
{
const char* p;
sceKernelDelayThread (10000);
if (client == 123)
p = "yes";
else
p = "no";
return p;
}
-------------------- code fragement end here ------------

the above is a simple pure export module in that doc, As a C programmer, I know that the pointer p is a AUTO variable, It will be destroied when the function returned, I mean the p will point a Invaild area after the function returned, because p is nether a static pointer nor a heap poniter (use malloc), I worried this may cause the application crash?
why do this is safe in PSP, could someone tell me the reason, thank you!

do I make myself clear?
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Fri Apr 20, 2007 6:07 pm    Post subject: Reply with quote

You are not returning the address of P, you're returning what P points to. In this case, you are returning the address of a static string (in the text segment).
Back to top
View user's profile Send private message
picobsd



Joined: 19 Apr 2007
Posts: 18

PostPosted: Fri Apr 20, 2007 7:07 pm    Post subject: Reply with quote

jimparis wrote:
You are not returning the address of P, you're returning what P points to. In this case, you are returning the address of a static string (in the text segment).


Oh, thank you! It's const. I make a big mistake.
Back to top
View user's profile Send private message
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