gobo-eiffel / gobo

The Gobo Eiffel Project provides the Eiffel community with free and portable Eiffel tools and libraries.
https://sourceforge.net/projects/gobo-eiffel/
Other
59 stars 24 forks source link

Q: is there a way to print an object's memory address in Eiffel? #74

Closed mw66 closed 7 months ago

mw66 commented 7 months ago

I know Eiffel is not a raw language like C++, but just want to ask.

ebezault commented 7 months ago

Do you mean the size of the object in memory?

mw66 commented 7 months ago

No, the object's address, in C / C++, for struct Object object I want &object.

ebezault commented 7 months ago

Try that:

    f
        local
            s: STRING
        do
            s := "gobo"
            print ($s)
        end

Note that when compiled with ISE Eiffel, the garbage collector may move objects in memory.

mw66 commented 7 months ago

print ? Any IO class need to be inherited from?

tried:

io.put_string  ($(zone.implementation))
io.put_integer ($(zone.implementation))

ISE eiffel all reported: Syntax error.

BTW, any io.put_hex_integer method?

ebezault commented 7 months ago

print comes from ANY:

    print (o: detachable ANY)
            -- Write terse external representation of `o'
            -- on standard output.
        local
            s: READABLE_STRING
        do
            if attached o then
                s := o.out
                if attached {READABLE_STRING_32} s as s32 then
                    io.put_string_32 (s32)
                elseif attached {READABLE_STRING_8} s as s8 then
                    io.put_string (s8)
                else
                    io.put_string_32 (s.as_string_32)
                end
            end
        ensure
            instance_free: class
        end

$s is of type POINTER, so io.put_string or io.put_integer will not work. There is no io.put_hex_integer as far as I know.

mw66 commented 7 months ago

I can do print($zone), but cannot do print($(zone.implementation)) got Syntax error.

have to add local vars:

                        impl, impl2: EV_WIDGET_I

                        impl := zone.implementation
                        impl2 := zone.implementation_upper_zone
                        print($impl)
                        io.put_string("%N")
                        print($impl2)
                        io.put_string("%N")

Now, it works.

This syntax sucks.

ebezault commented 7 months ago

I can do print($zone), but cannot do print($(zone.implementation)) got Syntax error.

It works with gec.

This syntax sucks.

You are not supposed to access object addresses in Eiffel in the first place. Eiffel is not C :-)