http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

TheGrumpyProgrammer



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Pointing to the wrong thing......



Hi,
ok i'm not a expert programmer, so if i get anything wrong
don't shout at me :)


>int* _doStuff(int a, int b, int c, int d)
>{
>   int* results;
>
>   // do some stuff here to initalize the members of results.....
>
>   return results;
>}

Isn't it bad to return the address of a local varible...
once the function ends the varible will be taken from the
stack and the address would no longer be valide.

As ur other post stated you did actully malloc
the space?

lilke

int * results = (int *)malloc(sizeof(int));

right?

did you then at the end of the function free the
memory?

wouldn't that cause the memory location that the 
function returned become invalid?

would then it also mean the next time 
you call the function it allocates the same
peice of memory, therefore getting the
results u showed? 

Also is it strictly nessarey to use the
pointers...it mayde the function very messy...

Evan,


****
*Evan Marchant			       	
*ICQ#15055534			       					       	
*"Once one problems solved, ten are around the corner"
****
=================================================================
The GameProgrammer.Com mailing list is for the open discussion
of any topic related to the art, science, and business of
programming games. This list is especially tolerant of beginners.
We were all beginners once

To SUBSCRIBE or UNSUBSCRIBE please visit:
http://gameprogrammer.com/mailinglist.html