| |||||||||||||||||||||||||||||
|
On Jun 25, 2007, at 4:59 PM, Kevin Yohe wrote: > Hi, > > I am trying to define a constant table that can be initialized at > compile-time and linked into ROM. I had envisioned two ways of > defining > this; either > > struct sAggregate > { > int m0; > int m1; > int m2; > int m3; > }; > > const sAggregate table1[] = > { { 0, 0, 0, 0 }, > { 1, 1, 1, 1 }, > { 2, 2, 2, 2 }, > { 3, 3, 3, 3 } > }; As a POD type, this initialization is called static initialization (from constants) , which shall be performed at compile time (most implementation). > or > > struct sConstruct > { > int m0; > int m1; > int m2; > int m3; > > sConstruct( a0, a1, a2, a3 ) > : m0(a0), m1(a1), m2(a2), m3(a3) > {}; > }; > > const sConstruct table2[] = > { sConstruct( 0, 0, 0, 0 ), > sConstruct( 1, 1, 1, 1 ), > sConstruct( 2, 2, 2, 2 ), > sConstruct( 3, 3, 3, 3 ) > }; > On the contrary, this is not a POD type (user_declared constructors) , and is dynamic initialization happening at run time. 'cause this direct initialization might involve constructor resolution. Am I rit? >
| ||||||||||||||||||||||||||||
© 2004-2008 readlist.com