I'm implementing a stack-based virtual machine in C.
The following variables are used by pretty much every function:
- memory array
- various pointers to memory offsets
- program counter
- stack pointer
- frame pointer (less so)
Ordinarily, I'd avoid the use of globals. However, in this situation handing these around between functions seems cumbersome, particularly as I need to pass in a pointer to the pointers and counters to update them.
I could alternatively put them in a struct and hand that around.
This is by no means a performance constrained VM given the speeds of modern processors.
Would using globals be an acceptable or typical tradeoff in this particular scenario?