This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
c++ global object space
- From: "Kevin Yohe" <kevin at ssc-nh dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Mon, 9 Jul 2007 15:50:18 -0400
- Subject: c++ global object space
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