This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question about local variable


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]