This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Calculate the size of all variables
- From: Ian Lance Taylor <iant at google dot com>
- To: Le Ton Chanh <letonchanh at yahoo dot com>
- Cc: GCC Help <gcc-help at gcc dot gnu dot org>
- Date: Fri, 27 Mar 2009 07:50:44 -0700
- Subject: Re: Calculate the size of all variables
- References: <28587.97388.qm@web38101.mail.mud.yahoo.com>
Le Ton Chanh <letonchanh@yahoo.com> writes:
> I want to calculate the size of all variables in a function. I try with the following code but it doesn't run. Please help me. Thank you very much.
>
> int size_of_vars (fndecl) //fndecl is FUNCTION_DECL
> tree fndecl;
The comment says fndecl must be a FUNCTION_DECL (by the way, function
prototypes were standardized twenty years ago, it's OK to use them).
> {
> tree t;
> HOST_WIDE_INT total_size = 0;
> tree let = DECL_INITIAL (fndecl);
> for (t = BLOCK_VARS (let); t; t = TREE_CHAIN (t))
> total_size += int_size_in_bytes (TREE_TYPE (t));
>
> /* Process all subblocks. */
> for (t = BLOCK_SUBBLOCKS (let); t; t = TREE_CHAIN (t))
> total_size += size_of_vars (t);
Now you're calling it with T which is not a FUNCTION_DECL.
With all respect, you can answer this sort of question faster with a
little bit of debugging than you can by sending to a mailing list.
Ian