|
||
|
GP Mailing List
ATXGPSIG List
|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: Pointing to the wrong thing......
----- Original Message -----
From: Evan Marchant <evan@achaia.dircon.co.uk>
To: <gameprogrammer@gameprogrammer.com>
Sent: Sunday, May 07, 2000 5:42 PM
Subject: 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.
If you return a local variable its perfectly fine, if you return the address
of a local variable, then
your code is wrong. If you don't return a local variable what do you return?
You can return a
global variable, but thats just dumb, I guess return TRUE, FALSE, 0 is ok,
but local variables are
fine to return.
then you:
var = function(); to get its value
>
> 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
>
=================================================================
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
|
|