Page 1 of 1

Fixed address array definition not working?

Posted: Mon Mar 27, 2023 8:58 am
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.

Re: Fixed address array definition not working?

Posted: Mon Mar 27, 2023 11:29 am
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.

Re: Fixed address array definition not working?

Posted: Mon Mar 27, 2023 8:42 pm
by dom
Thanks for the report, I've pushed a fix + tests so will hopefully work now.

Re: Fixed address array definition not working?

Posted: Tue Mar 28, 2023 8:06 am
by DarkSchneider
Nice, thanks.

Re: Fixed address array definition not working?

Posted: Thu Apr 06, 2023 12:44 pm
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.

Re: Fixed address array definition not working?

Posted: Thu Apr 06, 2023 1:43 pm
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.

Re: Fixed address array definition not working?

Posted: Thu Apr 06, 2023 2:22 pm
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).