Re: c++ global object space

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

 




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 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