dimanche 7 juillet 2019

Generate unique integral type id for each type that is consistent between compilations

I am working on a library that, among other things, allows the serialization of PODs into a file to be loaded later and I need a way to preserve the type. The way i handle this now is via a template function that simply returns its address casted to an int. This works fine as long as I only run the same executable. If I change something and compile, it doesn't return the same number anymore. Probably because the linker placed those functions somewhere else which results in a different address being returned.

I know this is a long shot in C++ but is there a way to generate the same id's for each type even if code changes?

Aucun commentaire:

Enregistrer un commentaire