Fixed address array definition not working?

Other misc things
Post Reply
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Fixed address array definition not working?

Post by DarkSchneider »

Hi, I didn't reported as issue because I don't know if it is the intended behavior but I have this:

Code: Select all

char *newkey = (char*)0xfbe5;

printk("%x %x %x", newkey[7], *(char*)(0xfbe5 + 7), ((char*)0xfbe5)[7]);
Notice that 3 values should be the same, but the latest one is different. I am pretty sure (even asked to chatGPT that confirmed) in C language you can define arrays i.e. like:

Code: Select all

#define my_array ((type *)0xAAAA)
Then use it like normal variable array:

Code: Select all

my_arrai[i]
When assemble I see that the compiler always puts the base address, but while with the variable defined (the "newkey") it calls to l_gchar7, with the last method it calls to l_gchar instead.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Fixed address array definition not working?

Post by dom »

I think it's failing/failling through the gaps because it's being held as constant by the codegenerator. I'll fix it up. I have to admit I normally use the syntax: extern char arr[] @ 64000; so I wouldn't have come across this bug.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Fixed address array definition not working?

Post by dom »

Thanks for the report, I've pushed a fix + tests so will hopefully work now.
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Re: Fixed address array definition not working?

Post by DarkSchneider »

Nice, thanks.
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Re: Fixed address array definition not working?

Post by DarkSchneider »

Hi, the fix is already released?
Downloaded the latest one (v20789-c163a5749-20230406) and still get only the first value.
Also is there a way to use the way

Code: Select all

extern char arr[] @ 64000;
in a header file? I always get a duplicate definition error but I'd like to be global for anything including the header file, not defining it by itself in its code on C file.
User avatar
dom
Well known member
Posts: 2072
Joined: Sun Jul 15, 2007 10:01 pm

Re: Fixed address array definition not working?

Post by dom »

It should be in, the tests are here: https://github.com/z88dk/z88dk/commit/4 ... 4f0e1813bf with the results just below which matches what I would expect.

I've just tried it out your example now and it seems to work correctly and the generation again looks correct.

I think if you make arr static then it's not exported by multiple files.
DarkSchneider
Member
Posts: 71
Joined: Sun Apr 01, 2018 4:02 pm

Re: Fixed address array definition not working?

Post by DarkSchneider »

Ah OK my fault, when using native types works well.

In this case seems to fail because it is an union array:

Code: Select all

union memory_mapper_segment_info {
    struct { uint8_t segment; uint8_t slot_id; };
    dual unified;
};
typedef union memory_mapper_segment_info MemoryMapperSegmentInfo;

Code: Select all

#define RESOURCE_SEGMENT_ADDRESS 0xF9AE
Assigned correctly (not using the indexing that seems to fail), but when reading:

Code: Select all

printk("\nsegment for scripts is %u and for sound is %u", ((MemoryMapperSegmentInfo*)RESOURCE_SEGMENT_ADDRESS)[RESOURCE_SEGMENT_TYPE_SCRIPT].segment, ((MemoryMapperSegmentInfo*)RESOURCE_SEGMENT_ADDRESS)[RESOURCE_SEGMENT_TYPE_SOUND].segment);
I get always the fist value.

And yes doing the "static char arr[] @ address;" works well and don't get duplicate error.
My doubt is if that is ANSI-C or works on SDCC (not tested yet).
Post Reply