Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Variable on stack or heap?

On 7 Nov 2009, at 17:09, Gavin Rehkemper wrote:
So you're saying that because of this particular case we can never know if pInt is on the stack or heap? Is there a way to check the last assignment?

How would you know which comes last without running it? An AST is for one translation unit only remember - a global (for example) could also be changed elsewhere. Statically tracing the execution path of a non- trivial program is virtually impossible.

Pete, we are writing an eclipse plugin that is doing some intelligent code refactoring. To take an example, say we're trying to get the size of an array. We could either use sizeof() or malloc_usable_size() - and we want to figure out which one to use given a particular variable.

You can tell the difference between a pointer and an array statically, but not if it's been passed to a function or cast to something else. After all, a function taking a pointer could be called with both malloc'ed and array-based memory in the same program...

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



Back to the top