Skip to content

Instantly share code, notes, and snippets.

@MartelliEnrico
Last active December 17, 2023 05:44
Show Gist options
  • Save MartelliEnrico/de3063d9956a85712116 to your computer and use it in GitHub Desktop.
Save MartelliEnrico/de3063d9956a85712116 to your computer and use it in GitHub Desktop.
C defer for GCC
#pragma once
#define defer_(x) \
void _dtor_##x(); \
int __attribute__((cleanup(_dtor_##x))) _dtorV_##x; \
void _dtor_##x()
#define defer__(x) defer_(x)
#define defer defer__(__COUNTER__)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment