Walter Bright wrote:
grauzone wrote:
Walter Bright wrote:
bearophile wrote:
Walter Bright:
There are significant technical problems with having functions return tuples.<

A possibly stupid question: isn't it enough to return a custom struct?

No, because of the alignment mismatches with other uses of tuples.

I don't understand, what does alignment have to do with such a high level construct?

You can use a tuple to populate a struct with fields, and it's interchangeable with manually populating the fields. You can also use a tuple to pass args to a function, and it's interchangeable with manually listing the args.

But if you populate a struct with a tuple, then pass the struct as an arg, it is *not* interchangeable with manually listing the args, as the alignment is different.

Again, I can't understand. Does the compiler rely that tuples have the same byte layout as structs or function arguments? I thought the compiler could just copy all fields. And the backend can already return multiple values, since it can return structs and static arrays.

That aside, I'm also glad that you acknowledge that current tuples are not perfect and need improvement. It's probably already too late to fix them, but you could always introduce a second, proper tuple type.

Reply via email to