In the previous post https://gustedt.wordpress.com/2020/12/14/a-defer-mechanism-for-c/ I already presented an idea for a defer feature for C, namely a feature that would provide a simple mechanism to cleanup at the end of a block, regardless how that block is left. There are many different extension out there that provide such a feature, for example POSIX’
__finally and gcc’s
cleanup attribute. Although they are used quite often, none of these extension has yet been adopted widely enough to prefer it over the others for standardization.
In a new paper
we present a much simpler version of a unifying framework for such cleanup features which is conditionned to the acceptance of lambdas into C23:
defer lambda-expression;Continue reading “A defer feature using lambda expressions”