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]

c++ const aggregate vs constructor


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

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 )
};

I am wondering if these two definitions are logically equivalent.  

Is the gnu c++ compiler smart enough to initialize these tables at
compile-time or are they actually initialized after the data is copied into
ram?

Background:  I am writing some boot code that has the task of configuring
and initializing some SDRAM.  The boot code has a limited amount of SRAM to
play with.  Since these tables are constants I would like to store them in
ROM.  How do I force the linker to put them in ROM?  How do I ensure that
the table is initialized?

Thanks,

Kevin 



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