[Z88dk-users] Understanding arrays and the stack

Bridge to the z88dk-users mailing list
Post Reply
WauloK
Member
Posts: 63
Joined: Thu Oct 10, 2019 10:45 am

[Z88dk-users] Understanding arrays and the stack

Post by WauloK »

Hi.

I figured rather than filling up the forum it might be better to ask here.
I had this reply from Dom:
------
int i,j,fontdatastart,textchar; int fontoffset,arrayoffset; char
fontarray[];
Which defines an array with 0 elements - i.e. it consumes no space on the
stack. So you've got on the stack:
sp+0 = fontarray
sp+0 = arrayoffset
sp+2 = fontoffset
And then you've got:
fontarray[0] = fontspec.width;
fontarray[1] = fontspec.height;

Which will overwrite array offset with the value 7 * 256 + 5 = 1797
=====
I want to understand when things get added to the stack and if it's not
possible to declare an array but not set a size since it won't grow by
pushing other variables down, but will overwrite other variables.
Should I use malloc to set the array size since I don't know at the start
how large the array size will need to be until a separate file with array
data is read in?
Does declaring fontoffset and arrayoffset not reserve the space of an int?
Are arrays with no size declared not usable with z80 C programming?
For other code reference, this is from:
https://www.z88dk.org/forum/viewtopic.php?id=11050

I tried using malloc then got an error saying missing _heap so I read I
need to declare "long heap" which I did, then I read I need "void
mallinit(void)" and now my code doesn't run at all.

Thanks.
--
https://JasonOakley.com/ - Voice acting and geeky stuff
<http://AussieTechHeads.com.au/>
https://OziByte.com - Fitbit Ionic clock faces and games
<http://AussieTechHeads.com.au/>
http://AussieTechHeads.com.au/ - Australian technology podcast
https://www.facebook.com/RetroRegeneration/ - My retro 80s radio show
https://BlueBilby.com/ - My retro VZ200 website
Post Reply