Re: question about local variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux