Skip to main content
Mod Moved Comments To Chat
Active reading. [<http://english.stackexchange.com/questions/4645/is-it-ever-correct-to-have-a-space-before-a-question-or-exclamation-mark#comment206109_4645> ]
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

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 :)

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 function to see how it react :)

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 functions to see how it react :)

deleted 10 characters in body
Source Link
Tom's
  • 2.5k
  • 1
  • 14
  • 25

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);true;} bool Do2(void) { printf("function %s\n", __func__); return (true);true;} bool Do3(void) { printf("function %s\n", __func__); return (false);false;} bool Do4(void) { printf("function %s\n", __func__); return (true);true;} bool Do5(void) { printf("function %s\n", __func__); return (true);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 function to see how it react :)

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 function to see how it react :)

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 function to see how it react :)

Source Link
Tom's
  • 2.5k
  • 1
  • 14
  • 25

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 function to see how it react :)