Created
March 11, 2014 22:38
-
-
Save johnbartholomew/9496567 to your computer and use it in GitHub Desktop.
GNU C supports using compound statements as expressions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) { | |
if (argc < 2) { | |
fprintf(stderr, "usage: check x|y\n"); | |
return 1; | |
} | |
const int is_x = ({ | |
int _x; | |
if (strcmp(argv[1], "x") == 0) | |
_x = 1; | |
else | |
_x = 0; | |
_x; | |
}); | |
printf("is_x = %d\n", is_x); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment