Is is possible in C to create structs “inline”?
typedef struct {
int x;
int y;
} Point;
Point f(int x) {
Point retval = { .x = x, .y = x*x };
return retval;
}
Point g(int x) {
return { .x = x, .y = x*x };
}
f
is valid, g
not. Same applies to function calls:
float distance(Point a, Point b) {
return 0.0;
}
int main() {
distance({0, 0}, {1, 1})
}
Is it somehow possible to create these structs without having to use the extra temporary variable (which will be optimized away by the compiler i guess, but readability counts too)?