Compare C Generic Techniques and C++ Smart-Pointer Ownership
Company: Netapp
Role: System Software Engineer
Category: Software Engineering Fundamentals
Difficulty: easy
Interview Round: Technical Screen
## Interview Prompt
Explain how C can implement type-generic operations with `void *`, macros, and
function pointers, and why C does not provide native function overloading. Then
compare `unique_ptr` and `shared_ptr`, show how unique ownership disables copying,
and describe the control block and weak-reference mechanism behind shared
ownership.
### Constraints & Assumptions
- Address type safety, lifetime, code generation, and debugging trade-offs.
- Assume modern C++ move semantics are available.
- Do not treat a raw pointer as an ownership policy by itself.
### Clarifying Questions to Ask
- Is compile-time type checking required for the C interface?
- Can the generic operation accept a callback for comparison or destruction?
- Are shared ownership cycles possible in the object graph?
### What a Strong Answer Covers
- Accurate contrast among untyped `void *`, macro substitution, and callback-based APIs.
- Explanation that C symbols lack signature-based language overloading, with naming or `_Generic` as alternatives.
- Deleted copy operations and move transfer for unique ownership.
- Strong and weak counts, object destruction, control-block lifetime, and cycle avoidance.
- Awareness of allocation, atomic-reference-count, and concurrency costs.
### Follow-up Questions
- What problem does `make_shared` solve, and what lifetime trade-off can it create?
- When is a custom deleter necessary?
- How would you expose a C API without losing type-specific cleanup?
Overview: Compare type-generic techniques in C using void pointers, macros, and callbacks with ownership mechanisms in modern C++. Explain why C lacks native overloads, then contrast unique and shared smart pointers, move-only ownership, control blocks, weak references, and cycle risks.
Read the full Netapp System Software Engineer interview experience this question came from