Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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