MichaelMeissner
Senior Member+
Michael,
Deviating slightly, let me turn the problem around.
If I wanted, as it is with T3, all program code and constants in Flash and only non-constant data in RAM, how should I instruct compiler and linker?
Reason: Contrary to suggested RAM based execution, I would like to use RAM for data buffer.
For normal data, just use the const keyword. I.e.
Code:
static const char array[] = "test";
Note however, due to the inside out way C/C++ data declarations are done, the const and volatile go to the results of a function or what a pointer points to, and not the base item. I.e. this means ptr1 itself is in read/write memory, but the compiler will not let you write to the address the pointer points to (i.e. data1).
Code:
static const int data1[] = { 1, 2, 3, 4 };
static const int *ptr1 = &data1[0];
This means ptr2 itself can not be modified, but you can modify what the pointer points to:
Code:
static int data2[] = { 1, 2, 3, 4 };
static int *const ptr2 = &data2[0];
This means ptr3 itself cannot be modified, and you can't modify what the pointer points to:
Code:
static const int data3[] = { 1, 2, 3, 4 };
static const int *const ptr3 = &data3[0];
This fragment shows what can be done. The functions that are commented out are illegal, and the compiler will flag them as an error:
Code:
static const int data1[] = { 1, 2, 3, 4 };
static const int *ptr1 = &data1[0];
void set_ptr1 (int n)
{
ptr1 = &data1[n];
}
// void mod_ptr1 (void)
// {
// *ptr1 = 10;
// }
const int *ret_ptr1 (void)
{
return ptr1;
}
// =======================================
static int data2[] = { 1, 2, 3, 4 };
static int *const ptr2 = &data2[0];
// void set_ptr2 (int n)
// {
// ptr2 = &data2[n];
// }
void mod_ptr2 (void)
{
*ptr2 = 10;
}
int *ret_ptr2 (void)
{
return ptr2;
}
// ======================================
static const int data3[] = { 1, 2, 3, 4 };
static const int *const ptr3 = &data3[0];
// void set_ptr3 (int n)
// {
// ptr3 = &data3[n];
// }
// void mod_ptr3 (void)
// {
// *ptr3 = 10;
// }
const int *ret_ptr3 (void)
{
return ptr3;
}
This is all for the standard way things are set up by the compiler and linker. Obviously Paul may have made modifications of how things are done in the T4. While I'm on the beta list, I didn't have time to fiddle with the early beta types, and told Paul/Robin to put me on the later list. So I don't have a T4 at this point.