it will be interesting to see example for __tuple keyword
it’s not entirely clear what it is and how to use it
and for now it’s beta
then the help doesn’t work
it will be interesting to see example for __tuple keyword
it’s not entirely clear what it is and how to use it
and for now it’s beta
then the help doesn’t work
Hi revs!
__tuple is a new keyword used in the type editor. It was introduced for a specific purpose: Golang functions returning multiple values.
When a function returns a single value, things are pretty straight forward. It will be returned entirely in the registers (if there are enough of them available) or entirely on the stack. Returning multiple value (eg a tuple) is a bit more tricky, as some of the values can be returned in the registers, some in the stack. So, the main purpose of tuples is to specify multiple return values. When calculating return locations, tuples allow to place some fields in registers, some in stack.
Adding a tuple is easy, just make sure to check the corresponding box when adding a type:
And in the type editor, you can write, for example:
__tuple tuple1 {
int x;
int y;
int z;
}
If a function returns a tuple, you can edit the function to specify that, as tuple1 func();
Now, there’s a bit more about tuples going on internally, especially in the decompiler. For example, two tuples having the same type of fields are considered to be equal, regarding the names of these fields (x, y, z like in my example or a, b, c, it doesn’t matter).
The docs for this feature are still work in progress, but I hope in the meantime this post sheds some light onto the topic.
thank you
as far as I understand this is only applicable to golang
it won’t work for c++ via stack
it’s also not entirely clear which registers and in what order can be used for returning
as far as I’ve seen such cases
c++ compilers can do this, i.e. return some structures not via stack but via registers
but c++ compiler is not golang compiler
and they can use different registers to return an object
There is no need for tuples in C++, although are free to use them. Returning structs by value is already supported.