Snaipe / libcsptr

Smart pointers for the (GNU) C programming language
https://snai.pe/c/c-smart-pointers/
MIT License
1.57k stars 143 forks source link

How can you implement the great smart attribute?! #11

Closed eaglexiang closed 7 years ago

eaglexiang commented 7 years ago

It's so wonderful that you implement the smart type attribute!
Could you tell me how you did this? I can't find doc related to user defined type attribute for C/C++, but only user defined type.
Thank you very much!

Snaipe commented 7 years ago

smart is just a macro define that expands to __attribute__((cleanup(sfree_stack))). The cleanup variable attribute is documented as calling its parameter on the annotated variable when it goes out of scope.

I've written a more extensive blog post on the implementations of smart pointers w/ GNU C99, you might want to give it a read.

eaglexiang commented 7 years ago

Amazing! I've got the point.

thank you once again!