Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

importing linker addresses in c

I want to use an address named _end from the linker.ld file in main.c.
I know this address to be atleast 0x80000000. But when importing it like this extern char _end; in main.c and printing it I only get 17.
The linker.ld file is something like this :

SECTIONS {
    . = 0x80000000; 

/*some more code and sections (doesnt matter)*/

    _end = .;
}

Does anyone why this is happening or how I should import _end?
Thx in advance, jip.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It is a symbol only. You can only get its reference. You do not "import it"

extern char _end;

void foo(void)
{
     printf("%u", (unsigned)&_end);
}

or

extern char _end[];

void foo(void)
{
     printf("%u", (unsigned)_end);
}

For those who will complain about format and conversion. It is likely to be STM32 and nano library for this MCU does not support %zu and %p and sizeof(int) == sizeof(char *)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading