user2518461
user2518461

Reputation: 11

memory assignment for a structure with constant member

I'm programming embedded system with C language and I define a structure with two constant member "val" and "ptr".

typedef struct{
const u8 val;
u8 *const ptr;
}TEST;

If I declare such type variable as a global, would the variable be placed in ROM or in RAM?

TEST var;

Thanks

Upvotes: 1

Views: 1051

Answers (1)

Jamie Iles
Jamie Iles

Reputation: 141

The TEST instance needs to go into read/write memory - the TEST instance is non-const, even though all of it's members are const. GCC will emit the struct into .data which is read/write and the linker script should put this into the appropriate memory type.

'const' in C doesn't guarantee that the storage really is immutable - it only means that a program that performs strictly to the C standard won't have a 'const' item modified.

If you want data to go into ROM then you'll need an appropriate linker script that puts .rodata sections into ROM.

Upvotes: 2

Related Questions