why this code is executing properly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

why this code is executing properly

Jump to solution
642 Views
rahulkrishna
Contributor IV

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

Labels (1)
Tags (2)
1 Solution
487 Views
kef2
Senior Contributor IV

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.

View solution in original post

3 Replies
488 Views
kef2
Senior Contributor IV

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.

487 Views
rahulkrishna
Contributor IV

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?

0 Kudos
487 Views
kef2
Senior Contributor IV

__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.