question about local variable
Eljay Love-Jensen
eljay@adobe.com
Wed Jul 21 13:35:00 GMT 2004
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
More information about the Gcc-help
mailing list