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: c++ global object space



Kevin Yohe schrieb:
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?

Yes.


[...] 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?

I am pretty sure that it is executed at run-time during global object initialization. However, to be sure I would just write a small test program, compile it and check the resulting assembly code with objdump.


Daniel


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