If you have the same signature for your function you can do something like this :
bool Do1(void) { printf("function %s\n", __func__); return true;} bool Do2(void) { printf("function %s\n", __func__); return true;} bool Do3(void) { printf("function %s\n", __func__); return false;} bool Do4(void) { printf("function %s\n", __func__); return true;} bool Do5(void) { printf("function %s\n", __func__); return true;} void Undo1(void) { printf("function %s\n", __func__);} void Undo2(void) { printf("function %s\n", __func__);} void Undo3(void) { printf("function %s\n", __func__);} void Undo4(void) { printf("function %s\n", __func__);} void Undo5(void) { printf("function %s\n", __func__);} typedef struct action { bool (*Do)(void); void (*Undo)(void); } action_s; int main(void) { action_s actions[] = {{Do1, Undo1}, {Do2, Undo2}, {Do3, Undo3}, {Do4, Undo4}, {Do5, Undo5}, {NULL, NULL}}; for (size_t i = 0; actions[i].Do; ++i) { if (!actions[i].Do()) { printf("Failed %zu.\n", i + 1); for (int j = i - 1; j >= 0; --j) { actions[j].Undo(); } return (i); } } return (0); } You can change the return of one of Do functionfunctions to see how it react :)