How common is stack machine use in C++ code?

292 views Asked by At

I'm looking at some C++ code and it includes a stack machine for scripting. I learnt C++ years ago, but never used it in my day job, so I don't have any real idea if this is common practice, or is it only used under certain very specific circumstances?

1

There are 1 answers

0
Mats Petersson On

If you need to evaluate expressions such as 2 + 3 * 7 or x = a + b / sin(c), then a stack oriented approach will work quite well.

I wouldn't say it's overly common. I know that Emacs being built around a lisp interpreter, which in turn is typically implemented as a stack-machine, I'm not sure I know of anything that uses this approach. But that's not to say that in SOME areas this isn't in common use.

Looking/thinking about it I also think that Java VM is essentially a stack machine, as is PostScript (and by extension PDF interpreters, since the concept is based on a simplified PostScript format).