A lightweight implementation of a unique pointer in C, providing automatic memory management and type-safe operations.
- Automatic memory management
- Type-safe operations
- Support for basic data types (char, int, float, double)
- Simple API for pointer manipulation
- Print functionality with automatic type detection
Initializes a new unique pointer with the given data.
u_ptr* u_ptr_init(void* ptr, size_t size, dataType type);
Retrieves the data stored in the unique pointer.
void* u_ptr_get(u_ptr* ptr);
Prints the data stored in the unique pointer with automatic type detection.
void u_ptr_print(u_ptr* ptr);
Resets the unique pointer to NULL and sets the Size to 0
void* u_ptr_reset(u_ptr* ptr);
int i_val = 123;
u_ptr* i_ptr = u_ptr_init(&i_val, sizeof(i_val), INT);
u_ptr_print(i_ptr); // Prints: 123
u_ptr_reset(i_ptr);
free(i_ptr);
The project can be built using any standard C compiler:
gcc main.c src/u_ptr.c -o u_ptr
cl main.c src/u_ptr.c /I. /Zi
- Implement automatic memory deallocation when pointer goes out of scope
- Add support for more data types
- Implement move semantics
- Add array support