Re: [cc65] Accessing linker symbols from C?

From: thefox xofeht <thefox1aspekt.fi>
Date: 2011-11-17 20:22:49
On Thu, Nov 17, 2011 at 9:18 PM, thefox xofeht <thefox@aspekt.fi> wrote:
> On Thu, Nov 17, 2011 at 9:01 PM, Joseph Rose <rose.joseph12@yahoo.com> wrote:
>> How do I, from C code, access symbols from the linker?  Let's say I create a
>> buffer in memory as a segment and want to fill it with a document.  The
>> problem is that when I try to read the starting address of a defined memory
>> segment (i.e. __BSS_LOAD__), I get a zero value.  I need the starting
>> address and size of the segment.  BTW, I know to remove the initial '_' and
>> have been defining the label as extern in a header.
>
> I don't know if there's a better way to do this (probably not), but
> from C's point of view everything is an address. If you do something
> like "extern int foo;" and then try accessing "foo", it will read an
> int from the address marked by the symbol "_foo". So to get what you
> should do something like this:
>
> extern void _BSS_LOAD__;
> int bss_load = ( int )&_BSS_LOAD__;

I'll just add (once again) to my own post, that you could also do
something like this...

extern unsigned char _BSS_LOAD__[];

...and then access it as an array. For some reason I forgot that
__BSS_LOAD__ is indeed an address and not an integer when writing the
earlier post... Anyway, the principle stands.

-thefox
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Thu Nov 17 20:22:57 2011

This archive was generated by hypermail 2.1.8 : 2011-11-17 20:23:00 CET