__attribute__((cleanup()))

#include <iostream>
//$ g++ sandwitch.cpp
//$ ./a.out]
using namespace std;

void cnup(int* i){
  cerr << __func__ << endl;
}
void _init(void){
  __attribute__((cleanup(cnup))) int i;
}
int main(){
  {__attribute__((cleanup(cnup))) int i; }
  _init();
  cerr << __func__ << endl;
};

二ヶ所でスコープ外しに挑戦してるんだけどなんでダメなんだろ。C++だからマングリングの問題かと思ってextern "C"つけてもダメだった。

The cleanup attribute runs a function when the variable goes out of scope.