[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] Variable on stack or heap?
|
Gavin Rehkemper wrote:
We have a variable, and we know it is a pointer. How do we determine
whether it points to something allocated on the heap (malloc'd, for
example), or something allocated on the stack (an array of finite length).
In the general case this is not possible from an AST, as it must be
determined at run-time (pointers can be changed to point at other
things, for example).
If the specific scenario is *very* simple, you could look for all the
assignments in the AST and *may* be able to determine from that exactly
what it is pointing to after the assignment completes. Probably not
very likely or useful though.
At run-time you might be able to do this by checking the address that it
points to, assuming you know where the stack and heap are in memory.
What are you actually trying to achieve, if you don't mind me asking?
Pete
--
Peter J. Vidler
Senior Systems Developer, TTE Systems Ltd
p.vidler@xxxxxxxxxxxxxxx
+44 (0)116 223 1684
Registered address: 106 New Walk, Leicester, LE1 7EA
Company number: 05058157
VAT registration: 913 4859 12
www.tte-systems.com