12 ms·
Sorry to be blunt -- I mean no offense, we all started somewhere. To me, it reads like a beginners experiment. All that #pragma stuff, that first param ('zero
by beeforpork 9y ago
Sorry to be blunt -- I mean no offense, we all started somewhere. To me, it reads like a beginners experiment. All that #pragma stuff, that first param ('zero') that is all not needed for the effect. The 'zero' and 'return;' stuff reads to me like someone is assuming typeof() evaluates its argument so someone must do somethings against it executing. It looks bloated with stuff a beginner does not realise is unnecessary.
I suppose the point is to declare a tuple directly as a return type without a typedef. Then, to return a value, use 'typeof' to declare a return variable of that anonymous type. So, the whole point is to avoid a typedef, I think:
typedef struct { int x; int y; } foo_result_t;
foo_result_t foo(int a, int b) {
return (foo_result_t){ a*a, a/b };
}
int main(void) {
foo_result_t a = foo(40,2);
}
Instead of typedef, use typeof and __auto_type. Without the bloat:
struct { int x; int y; } foo(int a, int b)
{
typeof(foo(a,b)) out = { a*a, a/b };
return out;
}
int main(void) {
__auto_type a = foo(40,2);
}
It is a bit underwhelming. But it tought me something: I did not know GCC's (and Clang's?) __auto_type extension (new since gcc 4.9, apparently). It looks great for compiler specific magic macros! :-)