Handmade Hero»Forums»Code
34 posts
I am fully functional, programmed in multiple techniques.
_cleanup_free_ for MSVC?
GCC/Clang have an extension _cleanup_<foo>_ which allows function <foo> to be called on a variable when you leave scope. This is really handy for marking pointers such that their memory is guaranteed to be freed, eg.:

1
2
#define _cleanup_free_ __attribute__((cleanup(freep)))
static inline void freep(void *p) { free(*(void **)p); }


Is there an analagous feature in MSVC?
Mārtiņš Možeiko
2380 posts / 2 projects
_cleanup_free_ for MSVC?
Edited by Mārtiņš Možeiko on
There's no way to do that in C with MSVC. Microsoft wants you to use C++ instead for this.
34 posts
I am fully functional, programmed in multiple techniques.
_cleanup_free_ for MSVC?
mmozeiko
There's no way to do that in C with MSVC. Microsoft wants you to use C++ instead for this.


Thanks, I thought as much. I'll just abstain from weird features in code that's meant to be portable. :D