# How to check whether 2 symbols are indeed pointing to the same object?

**URL:** <https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553>\
**Category:** General Usage\
**Created:** [November 26, 2019, 9:46pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553 "2019-11-26T21:46:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 26, 2019, 9:46pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553/1 "2019-11-26T21:46:22Z")

</div>

```nohighlight
julia> struct MM
           x::Int
       end

julia> Base.:(==)(m1::MM,m2::MM) = m1.x == m2.x

julia> m1 = MM(3)
MM(3)

julia> m2 = MM(3)
MM(3)

m1 == m2 #returns true

```

I am looking for a way to check whether m1 and m2 identifiers are really pointing to the same object in memory…

---

<div class="post-metadata">

**Author:** ![jkbest2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jkbest2/32/7350_2.png) [@jkbest2](https://discourse.julialang.org/u/jkbest2)\
**Post date:** [November 26, 2019, 9:48pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553/2 "2019-11-26T21:48:27Z")

</div>

I think [the `===` operator](https://docs.julialang.org/en/latest/base/base/#Core.:===) is the standard approach.

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 26, 2019, 9:49pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553/3 "2019-11-26T21:49:24Z")

</div>

julia\> m1 === m2  
true

that doesn’t work. Should I override it? if so how?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [November 26, 2019, 9:58pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553/4 "2019-11-26T21:58:45Z")

</div>

`===` is the only notion of identity that exists in Julia. I believe the exact condition is that two objects are `===` if no well-formed program could distinguish them, which holds for your `m1` and `m2`. For isbits types, there is no identity beyond the actual data being stored.

Maybe if you explain what you actually want to accomplish we can help come up with a way to do it.

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [November 26, 2019, 10:14pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553/5 "2019-11-26T22:14:34Z")

</div>

I am merely trying to do a variable aliasing analysis on the AST level & runtime checks.  
I am assuming there must be a way to get around it using Julia runtime. (Some C handle )???

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [November 26, 2019, 10:57pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553/6 "2019-11-26T22:57:45Z")

</div>

Unlike in C(++), Julia variable names simply do not map 1-to-1 to memory addresses. As a result, this information is just not available at the language level. This is especially relevant in the case of `isbitstype` `struct`s, like the one in the original post. You can inspect the generated code to see what will happen at that level (which may depend on optimization flags, etc.), but your exact question just doesn’t have a well-defined answer.

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [November 26, 2019, 11:17pm UTC](https://discourse.julialang.org/t/how-to-check-whether-2-symbols-are-indeed-pointing-to-the-same-object/31553/7 "2019-11-26T23:17:47Z")

</div>

Are you looking for

```julia
mutable struct MM
    x::Int
end

```

maybe? Two instances of `mutable` data structures _can_ be distinguished from one another.
