Skip to content

Instantly share code, notes, and snippets.

@johnbartholomew
Created March 11, 2014 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbartholomew/9496567 to your computer and use it in GitHub Desktop.
Save johnbartholomew/9496567 to your computer and use it in GitHub Desktop.
GNU C supports using compound statements as expressions.
#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