Skip to content

Instantly share code, notes, and snippets.

@a2gs
Last active March 16, 2019 05:19
Show Gist options
  • Save a2gs/2d0e6750c9ce15edc92329d3b5682185 to your computer and use it in GitHub Desktop.
Save a2gs/2d0e6750c9ce15edc92329d3b5682185 to your computer and use it in GitHub Desktop.
exit() vrs return() into main()
#include <stdio.h>
#include <stdlib.h>
static char *message;
void cleanup(void)
{
printf("message = \"%s\"\n", message);
}
int main(int argc, char *argv[])
{
char local_message[] = "hello, world";
message = local_message;
atexit(cleanup);
#ifdef USE_EXIT
puts("exit(0);");
exit(0);
#else
puts("return 0;");
return 0;
#endif
}
@a2gs
Copy link
Author

a2gs commented Mar 15, 2019

Output:

$ gcc -DUSE_EXIT exit_vrs_return.c -o exit_vrs_return && ./exit_vrs_return
exit(0);
message = "hello, world"
$ gcc exit_vrs_return.c -o exit_vrs_return && ./exit_vrs_return
return 0;
message = ""
$

Code from: https://qr.ae/TWR8Ez
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment