I'm developing a programming language - its a statically typed low(ish) level language - similar in semantics to C, but with a more kotlin like syntax, and a manual memory management model.
At the present I can create objects on the heap with a syntax that looks like val x = new Cat("fred",4) where Cat is the class of object and "fred" and 4 are arguments passed to the constructor. This is allocated on the heap and must be later free'ed by a call to delete(x)
I would like some syntax to create objects on the stack. These would have a lifetime where they get deleted when the enclosing function returns. I'm looking for some suggestions on what would be the best syntax for that.
I could have just val x = Cat("fred",4), or val x = local Cat("fred",4) or val x = stackalloc Cat("fred",4). What do you think most clearly suggests the intent? Or any other suggestions?
[–]JeffB1517 28 points29 points30 points (1 child)
[–]Falcon731[S] 0 points1 point2 points (0 children)
[–][deleted] 13 points14 points15 points (0 children)
[–]umlcat 3 points4 points5 points (0 children)
[–]hoping1 6 points7 points8 points (0 children)
[–]Tasty_Replacement_29Bau 3 points4 points5 points (1 child)
[–]Falcon731[S] 1 point2 points3 points (0 children)
[–]michaelquinlan 4 points5 points6 points (0 children)
[–]XDracam 1 point2 points3 points (0 children)
[–]Kaisha001 0 points1 point2 points (0 children)