 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
picobsd
Joined: 19 Apr 2007 Posts: 18
|
Posted: Fri Apr 20, 2007 5:53 pm Post subject: Question of function return value |
|
|
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 |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Fri Apr 20, 2007 6:07 pm Post subject: |
|
|
| 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 |
|
 |
picobsd
Joined: 19 Apr 2007 Posts: 18
|
Posted: Fri Apr 20, 2007 7:07 pm Post subject: |
|
|
| 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 |
|
 |
|
|
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
|