Skip to content

Instantly share code, notes, and snippets.

@akoskovacs
Created January 20, 2017 19:06
Show Gist options
  • Save akoskovacs/8c3cc10e9e9daaad0cd880ea4279d67c to your computer and use it in GitHub Desktop.
Save akoskovacs/8c3cc10e9e9daaad0cd880ea4279d67c to your computer and use it in GitHub Desktop.
Implementing if statement in GNU C with goto
#include <stdio.h>
/*
* if (argc == 1) {
* printf("argc equals one\n");
* } else {
* printf("argc is not one (%d)\n", argc);
* }
* return argc;
*/
int main(int argc, const char *argv[])
{
goto *((argc == 1) ? &&argc_one : &&argc_other);
argc_one:
printf("argc equals one\n");
goto end;
argc_other:
printf("argc is not one (%d)\n", argc);
goto end;
end:
return argc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment