I want to make 64 4-Byte long array and I want the start address to be what I want, say 0x1000_0000
.
int wspace[64]; //this makes a 64 int array
I want wspace
to be located at a particular location of my choice.
How Can I do that?
I want to make 64 4-Byte long array and I want the start address to be what I want, say 0x1000_0000
.
int wspace[64]; //this makes a 64 int array
I want wspace
to be located at a particular location of my choice.
How Can I do that?
You're starting to get into a grey area of possibly undefined behaviour but, if you know what you're doing (such as if you're on an embedded system and you have memory-mapped I/O or other valid writable stuff at that location), then you can just try:
int *wspace = (int *)0x10000000;
Depending on your compiler and environment, you may want to mark it as volatile as well, so that the implementation understands the memory may change independently of anything done to it by said compiler:
volatile int *wspace = (volatile int *)0x10000000;
It's not technically an array but, unless you're going to do something like sizeof
on it, that probably won't really matter.
Once you've done that, then a statement like wspace[1] = 0x12345678
should write that value to memory locations 0x10000004-0x10000007
(for a 4-byte int
). Just keep in mind that which part of the number goes into which memory location will depend on the endian-ness of your architecture.
You can create a section in the linker file which start at this address and put this variable only in this section, the possibility of doing this will depend on your architecture.