Don't use arrays as stacks
Jonathan M Davis
jmdavisProg at gmx.com
Sat Sep 24 23:45:36 PDT 2011
On Sunday, September 25, 2011 02:37:25 Nick Sabalausky wrote:
> If anyone cares, I've put up a little thing about why it's best not to use
> D's arrays as stacks. This is drawn from a direct experience a few months
> ago. Figured if I fell into that trap then others might too, so this could
> be helpful for some people. There's a no-login-needed comments section
> already there.
>
> https://www.semitwist.com/articles/article/view/don-t-use-arrays-as-stacks
Yeah. If you want to use an array for a stack, it really needs to be wrapped
in a struct or class like you'd do in C++. Expanding it when the size of the
array needs to increase to accomodate items pushed onto the stack is certainly
much easier in D, but trying to use the array as a stack directly is definitely
going to cause issues as you show in the article.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list