2 ms·
You see &variable in a function body, you allocate a stackframe for that in the heap abstraction and return that’s address.
by kaba0 4y ago
You see &variable in a function body, you allocate a stackframe for that in the heap abstraction and return that’s address.
- Thiez 4y agoAnd now for a reference to a field in a struct living on the heap? Of course you can get C to run on the JVM (any CPU emulator written in Java proves that) but due to JVM limitations you cannot do so efficiently. Which is why it the JVM is not an attractive target for the 'traditional' languages.
- kaba0 4y agoThat struct on the heap is just consecutive bytes in an array, so you just return an integer.
- Thiez 4y agowarrenm was asking whether Java's (and implicitly: the JVMs) concept of references could be used. I'm glad that you agree with me that they cannot. Representing the memory of a compiled C program with a giant byte array would of course work, but also defeat the purpose of running on the JVM in the first place. You lose all the advantages that running on the JVM might have given you, and are slower than a natively compiled program.