3 ms·
It doesn't have to be a return value though. You could pass pointers to it as parameters. To answer the question though, a number of people do define structur
by asveikau 7y ago
It doesn't have to be a return value though. You could pass pointers to it as parameters.
To answer the question though, a number of people do define structures containing a buffer and a length (and potentially capacity), there just isn't such a structure standardized so everybody who wants to do this has to bring their own.
Some examples from Unix: iovec, sendmsg/recvmsg. Surely there are others I'm just not thinking of right now.
In the Windows world you have UNICODE_STRING and similar structures. SChannel has "PSecBufferDesc". Again, surely there are others.
And prominent libraries might also have their own.
- int_19h 7y agoPassing struct arguments by value is also complicated in some ABIs. The most reliable way is to pass a pointer to struct, but with slices that means double indirection. I don't think ABI is a concern these days, though, even if things were different 30 years ago. The specs that we have today do cover how to pass and return structs in the standard manner.