[Z88dk-users] Problem with structs and function pointers

Bridge to the z88dk-users mailing list
Post Reply
overCLK
New member
Posts: 2
Joined: Wed Sep 13, 2017 7:19 pm

[Z88dk-users] Problem with structs and function pointers

Post by overCLK »

Hello. I've hit a problem while trying to use structs holding function pointers. I don't know if I made something wrong, but at the end I figured out that the alignment of the elements seems to be wrong. I have written the following minimal example:

Code: Select all

extern void f0();
extern void f1();

struct {
void (*foo)();
unsigned char (*bar)();
} test[] = {
{f0, f1},
{f0, f1}
};
Compiling this to assembler by using:

Code: Select all

zcc +zx --c-code-in-asm -vn -a bugptr.c
leads to this assembler output:

Code: Select all

...
MODULE  bugptr


INCLUDE "z80_crt0.hdr"


;extern void f0();
;extern void f1();
;struct {
;void (*foo)();
;unsigned char (*bar)();
;} test[] = {
SECTION data_compiler

._test
;{f0, f1},an
defw    _f0
defw    _f1
defb    0
;{f0, f1}
defw    _f0
defw    _f1
defb    0
;};

SECTION code_compiler
...
The problem are those extra bytes at the end of each of the elements of the array. Surprisingly (at least for me), this only happens when the return type is defined as unsigned, what I really don't understand at all.

Can somebody put some light into this?

Thanks and best regards, :)
Manuel



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
User avatar
dom
Well known member
Posts: 1195
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

Hello. I've hit a problem while trying to use structs holding function pointers. I don't know if I made something wrong, but at the end I figured out that the alignment of the elements seems to be wrong. I have written the following minimal example:
Thank you for the minimal example. I think this issue is this one: https://github.com/z88dk/z88dk/issues/295

I can't reproduce it with the latest master.



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
overCLK
New member
Posts: 2
Joined: Wed Sep 13, 2017 7:19 pm

Post by overCLK »

Thank you for the minimal example. I think this issue is this one: https://github.com/z88dk/z88dk/issues/295

I can't reproduce it with the latest master.
Thanks for your fast answer. I've just downloaded the current nightly and the problem is gone!

Regards



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Post Reply