Hi,
i have written this code and expected the code to fail but it does not.
typedef unsigned char UINT8_T;
#define INDEX 100
#define NULL (void *)0
#pragma DATA_SEG __RPAGE_SEG PAGED_RAM
UINT8_T buffer[INDEX];
#pragma DATA_SEG DEFAULT
UINT8_T test_data[100];
UINT8_T *ptr_data=NULL;
void test(void)
{
UINT8_T fl_index_u8=0;
ptr_data = buffer;
for(fl_index_u8=0; fl_index_u8 < 100; fl_index_u8++)
{
buffer[fl_index_u8] = fl_index_u8;
test_data[fl_index_u8] = *ptr_data;
ptr_data++;
}
}
It compiled but with warning : C1860: pointer conversion: possible loss of data
I expected that test_data will be filled with default values of 0, but it is filling with data loaded into buffer variable. I am doing the full chip simulation, the address loaded into ptr_data = 0x00 and it is 2 bytes yet the progam is running successfully?
From the map file
ptr_data 2108 2 2 1 .bss
buffer FD1000 64 100 3 PAGED_RAM
test_data 210C 64 100 1 .common
What is the common area?
Thanks and regards
Solved! Go to Solution.
You should edit compiler settings and change C1860 message setting to produce compile error, not warning. Your code works because pointer dereference comes after access to buffer[], which sets up RPAGE register to the right value. Since both, buffer[] and *ptr_data are on the same RPAGE, you see data copied properly. Try defining more data, so that more than one R-page is used, also make ptr_data pointing to data, which is allocated on different R-page than buffer[].
Make sure there's -D__FAR_DATA in compiler command line switch. Project wizard may not include this important setting.
You should edit compiler settings and change C1860 message setting to produce compile error, not warning. Your code works because pointer dereference comes after access to buffer[], which sets up RPAGE register to the right value. Since both, buffer[] and *ptr_data are on the same RPAGE, you see data copied properly. Try defining more data, so that more than one R-page is used, also make ptr_data pointing to data, which is allocated on different R-page than buffer[].
Make sure there's -D__FAR_DATA in compiler command line switch. Project wizard may not include this important setting.
Thank you very much the reply. Now i understood. Can you please tell me or atleast point to the document which gives me some information about the switch you are referring to -D __FAR_DATA what does it do?
__FAR_DATA define is required to make startup file initializing paged data properly. Once you start using paged RAM, you need to have it defined, else startup code will try to init wrong memory areas.