array push() + pop()?

So there seem to be no array functions like push(). pop() splice(), etc. so I am wondering how folks store data sets of unknown length at runtime - and retrieve that data in a for loop through some eq. of myArray.length - 1?

The only idea that comes to mind right now is to init an array with a length large enough to accommodate any possible data set and keep a separate index to the position of the last stored value.

Am I missing some built in methods?

thanks!

–Roy

The only idea that comes to mind right now is to init an array with a length large enough to accommodate any possible data set and keep a separate index to the position of the last stored value.

I think that's pretty much your only choice. That'll be how any built-in stack operations end up working internally anyway. Note that microcontrollers like the AVR used in the arduino usually have quite a limited amount of ram, so you have to be pretty careful about how much you use.

mydatatype_t stack[MAXSTACKSIZE];
int stackptr = 0;
#define push(d) stack[stackptr++] = d
#define pop stack[--stackptr]
#define topofstack stack[stackptr - 1]

error checking might be a good idea :-)