AnsweredAssumed Answered

why this code is executing properly

Question asked by rahul krishna on Feb 4, 2015
Latest reply on Feb 4, 2015 by Edward Karpicz

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

Outcomes