In my linker script file, I have defined two symbols

define symbol _region_RAM_start__     = 0xC0000000;
define symbol _region_RAM_end__       = 0xC00fffff; 

and then I have exported them as well as shown below

export symbol _region_RAM_start__;
export symbol _region_RAM_end__;

From the application code, I try to access these symbols

extern const unsigned int _region_RAM_start__;
extern const unsigned int _region_RAM_end__;
....
int GetRAMSize()
{
    int size = 0;
    unsigned int address_1 = _region_RAM_start__;
    unsigned int address_2 = _region_RAM_end__;
    size = address_2 - address_1 + 1U;
    return size;
}

Now, I expected the return value to be 0x00100000, however, all I get is 0. So, when I turned to the debugger, I noticed that _region_RAM_start__ and _region_RAM_end__ have the values 0xC0000000 and 0xC00fffff respectively, but address_1 and address_2 have the value 0.

The compiler optimization is set to "None". This has been bugging me for a while now. Is there something very obvious I am missing here (other than "I should not be doing this in the first place")?

Solution Thanks to n.m. for the answer

  unsigned int address_1 = (unsigned int) (&_region_RAM_start__);

Otherwise address_1 and address_2 both contain garbage values (i.e. values available at the address 0xC0000000 and 0xC00fffff respectivly, but garbage from the point of view of this code)

Edit
Report