Skip to content

Instantly share code, notes, and snippets.

@jussi-kalliokoski
Created March 18, 2012 13:17
Show Gist options
  • Save jussi-kalliokoski/2072101 to your computer and use it in GitHub Desktop.
Save jussi-kalliokoski/2072101 to your computer and use it in GitHub Desktop.
Custom control structure 'detach' with accidental return.
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#define detach if (fork()); else for (;; exit(0))
int calculate () {
detach {
sleep(1);
return 5;
}
return 4;
}
int main () {
printf("Calculating.\n");
printf("Calculated: %d\n", calculate());
printf("Done.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment