0

Though this is asked at Compile-time constant id I want to ask here in the light of possibilities to get a unique id of an object class which can give insights on how the compiler works. As per my understanding, the symbols are unique binary names given to the identifiers, the functions names, the objects names, the variables which are translated to the addresses of the memory locations referred in expressions, the binary instructions during linking.

so the address of the static area of objects of a class can't be determined at compile time but however, we can determine a unique hash at both compile time and runtime. But typeid::hash_code() is not constexpr. Then what is its constexpr alternative?

I desperately need this unless there are reflections.

Necktwi
  • 2,483
  • 7
  • 39
  • 62
  • 1
    [There's an answer to that very post](https://stackoverflow.com/a/39640960/817643), which answers your needs too, I think. There's is no need to delve into implementation details. The C++ abstract machine makes those guarantees. – StoryTeller - Unslander Monica Jan 02 '18 at 07:52
  • Do you mean getting unique id of two different objects of the same type or unique id of two different types? – user7860670 Jan 02 '18 at 08:26
  • 2
    The unique id of a type is its fully qualified *name*. That is known at compile time. :-) Objects in general are not all known at compile time. For example objects created on the heap do not have a compile time id. And some of them might even have the same address at runtime, if they have different lifetimes. – Bo Persson Jan 02 '18 at 08:48
  • @StoryTeller I didn't believe that answer not only based on number of votes it got. It worked when I tested! – Necktwi Jan 02 '18 at 11:34
  • @StoryTeller it made me recollect how pointers are handled at compile time – Necktwi Jan 02 '18 at 11:38
  • Well, pointers or no pointers. Certain "addresses" the compiler can treat as compile time constant, even if it will only fill in the blanks later. That includes static variables, functions, and probably other things I'm forgetting. – StoryTeller - Unslander Monica Jan 02 '18 at 11:42
  • oh! that's nice of compiler! that's given me a new perception of compiler, I just thought its only the case with pointers, in fact I never thought of others. – Necktwi Jan 02 '18 at 13:55

0 Answers0