This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: question about local variable
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Serge MANIGAULT <serge dot manigault at ask dot fr>, gcc-help at gcc dot gnu dot org
- Date: Wed, 21 Jul 2004 08:34:30 -0500
- Subject: Re: question about local variable
- References: <NJEMLELKEDKMBLBGCEGICEOADFAA.serge.manigault@ask.fr>
Hi Serge,
For local variables at compile time, you need to use sizeof.
If you want to see the local variable size at link time, you'll have to do
a disassembly. And even then, it's tricky, because local variable names
will be hard to discern if debugging info is present, or highly difficult
without debugging information.
(For non-local variables, you can see the size in the nm dump.)
One bootstrapping trick that some programs use to determine the size of
certain objects -- such as needing to know the size to alter compilation
behavior via the preprocessor -- is to compile a small program that outputs
the size and then use that to create a compile time variable for the
application. For instance...
#include <iostream>
#include "MyStruct.h"
using namespace std;
int main()
{
cout << "#define MYSTRUCT_SIZE " << sizeof(MyStruct) << endl;
}
HTH,
--Eljay