Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

<><><> DELETING VARIABLES <><><>

0 views
Skip to first unread message

RIFurman

unread,
Dec 14, 1998, 3:00:00 AM12/14/98
to
I have a recursive function. I have a "static" variable in this function,
because the function is called many times, and also because the value shouldn't
change after the first time set. I would like to know how to delete this
variable, after I'm finished using it. The variable is an integer (if it
matters?!?). I am programming in C++, DOS (TC++ 3.0). Also, can a local static
variable be deleted by a different function, i.e. main() ?

Rob

Horst Kraemer

unread,
Dec 15, 1998, 3:00:00 AM12/15/98
to

Neither external nor static variables can be deleted in C or C++. Only
dynamic variables allocated by new/malloc can be deleted by
free/delete.

Why would you want to "delete" it ?


Regards
Horst


Stan Brown

unread,
Dec 16, 1998, 3:00:00 AM12/16/98
to
rifu...@aol.com (RIFurman) wrote:
>I have a recursive function. I have a "static" variable in this function,
>because the function is called many times, and also because the value shouldn't
>change after the first time set. I would like to know how to delete this
>variable, after I'm finished using it.
>[programming in C++]

A static variable is just that: space is allocated at the beginning of
execution and it stays there until the end of execution.

If you have data that you need to create and destroy, use new and delete
(the heap). Use static for permanent data (during program execution).

So the answer to your question is: there's no way; that's not how static
works.

--
Stan Brown, Oak Road Systems, Cleveland, Ohio, USA
http://www.concentric.net/%7eBrownsta/
"I'm not even supposed to BE here!" -- the mantra from /Clerks/
My reply address is correct as is. The courtesy of providing a correct
reply address is more important to me than time spent deleting spam.

0 new messages