z88dk forums

z80 Development Kit

You are not logged in.

#1 2019-11-01 05:22:10

WauloK
Member
Registered: 2019-10-10
Posts: 63

[Z88dk-users] Understanding arrays and the stack

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

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson