Is typeid safe being used on pointer provided by another process, which is compiled by the same compiler?

StackOverflow https://stackoverflow.com/questions/10289269

  •  02-06-2021
  •  | 
  •  

Domanda

According to the standard, typeid operator is implement dependent, so it's nonsense to use it on objects created by other processes compiled by different compiler. But what is the situation that the providing process is compiled by the same compiler?

È stato utile?

Soluzione

It probably won't work because the foreign object will contain a vtable pointer within its own process space, not that of the inspecting process. If you can form an address space where both executable binary images are in place as if they were the one running, then maybe. If it's the same version of the same compiler used with identical command-line flags, or if your platform ABI specifies exactly how typeid works at runtime, then you might be OK.

But strictly speaking, the C++ object model does not accommodate shared memory. You need to serialize before transmitting between processes, and there is no way to safely serialize a C++ type which might not exist on the receiving end.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top