in Rust. It's awesome to know that the C equivalent is
const int x = ({ if (y == 0) { return 1; } else { return 42; });
x ?: y =defn= x ? x : y
FILE *
concat_fopen (char *s1, char *s2, char *mode)
{
char str[strlen (s1) + strlen (s2) + 1];
strcpy (str, s1);
strcat (str, s2);
return fopen (str, mode);
}
- initialize specific indexes
int a[6] = { [4] = 29, [2] = 15 };
int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
- initialize struct fields:
//initialize struct fields
struct point { int x, y; };
struct point p = { .y = yvalue, .x = xvalue };
- initialize union variant:
union foo { int i; double d; };
union foo f = { .d = 4 };
- Neat trick: lookup for whitespace in ASCII:
int whitespace[256]
= { [' '] = 1, ['\t'] = 1, ['\h'] = 1,
['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
union foo { int i; double d; };
int x = 42; z = (union foo) x;
double y = 1.0; z = (union foo) y;
int x$;
int $z;
struct {
int a;
union { int b; float c; };
int d;
} foo