Answer by Harith for "Smart" (ish) pointer in C
Use a compound literal:C99 added compound literals for arrays, structs, and unions. Just as 42 specifies an int literal, a compound literal specifies a literal for an array, struct, or union. The...
View Article"Smart" (ish) pointer in C
I am a programmer with a primarily Rust-based background who has nonetheless taken an interest in C lately due to its simplicity and minimalism. However, one of the things I miss most from Rust is safe...
View ArticleAnswer by Ajinkya Kamat for "Smart" (ish) pointer in C
Disclaimer: The next few lines are my opinion as a C programmer so take it with a grain of salt.As a C programmer, I will never use this. The language is verbose enough already due to its lack of...
View ArticleAnswer by Lundin for "Smart" (ish) pointer in C
It isn't possible to implement smart pointers sensibly in C because it lacks "RAII". It would be possible to implement a garbage collector by multi-threading, but one of the benefits of using C in the...
View Article