Handmade Hero » Forums » Code » _cleanup_free_ for MSVC?
k2t0f12d
33 posts

I am fully functional, programmed in multiple techniques.

#9372 _cleanup_free_ for MSVC?
11 months, 1 week ago

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?

I could be chasing an untamed ornithoid without cause
mmozeiko
Mārtiņš Možeiko
1485 posts
1 project
#9373 _cleanup_free_ for MSVC?
11 months, 1 week ago Edited by Mārtiņš Možeiko on Nov. 15, 2016, 5:52 a.m.

There's no way to do that in C with MSVC. Microsoft wants you to use C++ instead for this.
k2t0f12d
33 posts

I am fully functional, programmed in multiple techniques.

#9374 _cleanup_free_ for MSVC?
11 months, 1 week ago

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

I could be chasing an untamed ornithoid without cause