_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?
There's no way to do that in C with MSVC. Microsoft wants you to use C++ instead for this.

Edited by Mārtiņš Možeiko on
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