How to get the address of a record variable? #84
-
To get the address of a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
You have printed the address of o.x there, it's 0x5574305962a0, this address is fixed, because it's inside the block of memory of the record. "record" really means a block of memory, so all variables inside a record have their addresses relative to the block of memory address. You can notice the address is also the same as the record address, this is because x is at the very start of the memory block region, so the very first field always has the same address of the record. |
Beta Was this translation helpful? Give feedback.
-
By the way, I have decided to tweak a bit my global configuration settings and use C++ in place of C; here's what I use for settings
and here is the actual output from Nelua:
Now, if I replace
Am I doing well that I use |
Beta Was this translation helpful? Give feedback.
-
@edubart I'm currently facing a very interesting issue with Nelua and I need your advice please. I have added another variable in require 'allocators.general'
require 'string'
local Object: type = @record{ x: integer, y: integer }
function Object:__close()
print(string.format('object %p destroyed', self))
general_allocator:delete(self)
end
do
local o: *Object <close> = general_allocator:new(@Object)
print(string.format('object %p created', o))
print(string.format("o.x initial value: %3d, address: %p", o.x, &o.x))
print(string.format("o.y initial value: %3d, address: %p", o.y, &o.y))
o.x = 10
print(string.format(" o.x new value: %3d, address: %p", o.x, &o.x))
end When I execute it, I get the following output:
This is exactly what I want to see. If I run it with TCC, I see a completely different format of addresses:
Now the action is about to begin for me. If I execute
Any idea why |
Beta Was this translation helpful? Give feedback.
You have printed the address of o.x there, it's 0x5574305962a0, this address is fixed, because it's inside the block of memory of the record. "record" really means a block of memory, so all variables inside a record have their addresses relative to the block of memory address. You can notice the address is also the same as the record address, this is because x is at the very start of the memory block region, so the very first field always has the same address of the record.