address of variable?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

address of variable?

code2win
This post was updated on .
How do I obtain the address of a given variable?
in C we would use &<var>
I can assign a memory address to an array variable using a literal, but if I don't know the address where a variable will be, how do I obtain that address?
Update:
looks like array var can only reference something on the heap (compiler error), so that's why docs only show array being used as a pointer to objects on the heap, not to the address of just any variable. Guess it's a safety feature for us not messing with the stack?
Why no general pointers?
Reply | Threaded
Open this post in threaded view
|

Re: address of variable?

WBahn
Administrator
The Jack language specification doesn't have that facility and, off the top of my head, I can't think of any way of tricking it into yielding that information.

You can trick it into giving you the address of objects, including Strings and Arrays, fairly easily. But getting the address of primitive variables is another matter.

You could, of course, always add that as a language extension and I don't think it would be too hard to do.