c++ global object space

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

 



Hello,

In c++, suppose I define a template class

typedef unsigned long tWord32;
	...
template<class T, tWord32 size>

class cBuffer
{
public:

	T	mBuff[size];
};

then declare a global,

cBuffer<tWord32, 512> longBuff;

Is &(longBuff.mBuff) known at link-time?

My hunch is yes.  My justification is below.

The result of the statement "cBuffer<tWord32, 512> longBuff;" is a template
class instantiation at compile-time, and a constructor invocation at
run-time.  At compile-time, during code generation, the compiler should know
the size of "longBuff", also the offset of the field "mBuff" should be
stored in order to generate code for a class field access expression.
Therefore the data space for the global object should be allocated at
compile-time during code-generation, meaning that the &(longBuff.mBuff) can
be resolved at link-time.

Are my assumptions correct?

Now suppose I did this,

template<class T, tWord32 size>

class cBuffer
{
public:
	T *   Address()
			{ return &mBuff; };

private:
	T	mBuff[size];
};

cBuffer<tWord32, 512> longBuff;

tWord32 * ptr = longBuff.Address();

Is the result of the inline method invocation expression
"longBuff.Address()" a push statement that gets executed during global
object initialization or is it treated as a field access expression and
resolved at compile-time?

Thanks,

Kevin M. Yohe II




[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