usefullness of shared_ptr in C interface
08:54 20 Feb 2026

I am new on a C++(20) project; which is a library. It exposes a plain-C interface for other languages to bind. The C interface is filled with wrappers like:

struct wrapper_object {
  template  wrapper_object(Args&&... args) : m_internal (std::forward(args)... ) {}
  std::shared_ptr < real_object> m_internal;
}

// simplified
int new_wrapper_object(wrapper_object** out)
{
    auto wrapper = make_unique();
    wrapper->m_internal = make_shared();
    *out = wrapper.release();
    return 0;
}

int delete_wrapper_object(wrapper_object* self)
{
    delete self;
}

I don't understand the purpose of this. The client code obviously cannot enforce shared_ptr semantics, so the only ref counting is done in C++ side. But we just made a fresh smart pointer out of nothing? There is no one on C++ side to share the ownership with?

I believe, this should either be a unique_ptr (when the Client actually manages the lifetime through delete_wrapper_object ) OR even a raw dumb pointer (when the Client has a readonly reference when the library doesn't expose a corresponding delete_.. function ).

(I am leaving aside the "make_unique ... release()" pattern which is also a wierd disguise for "new")

c++ c