My reading about std::unique_ptr
has convinced me that it (along with the other smart pointers) is definitely the best choice for pointers internally in a project (especially after Could an optimizing compiler remove all runtime costs from std::unique_ptr?), but I'm not sure yet about what to do at the interface. I don't fully grok how various C++ ABIs work, so please bear with me if this is a dumb question, but could functions that take or return pointers, classes/structs that have pointer members, etc. be replaced by something that uses unique_ptr
(maybe using unique_ptr
refs?) without requiring recompilation? Can C code interact with C++ interfaces using unique_ptr
without complication?
AFAIK, there's no guarantee that sizeof(unique_ptr<T>) == sizeof(T*)
, so no.
But even if it was the same size, there's also no guarantee that an arbitrary ABI will pass pointer arguments by the same mechanism as "value" arguments.