Array of custom type variable / Passing by ref a custom type variable

More
5 days 8 hours ago - 5 days 8 hours ago #173 by ludojoey
Hello!

I try to pass an array of custom type variable as a function parameter:

type myType {
   int a;
   int b;
};

void f(myType t) {
   t[0].a=1;
}

At compilation I get the error "Expect ) after [optional] params" on the line of function declaration.

In fact, at start, I wanted to pass a custom type variable by reference.
As it seems it is not possible, my "solution" was I could pass it as an array (as arrays are passed by reference) and then access it by the index "0".
 
Last edit: 5 days 8 hours ago by ludojoey.

Please Log in or Create an account to join the conversation.

More
5 days 7 hours ago #174 by Franck
Yep, passing an array of custom type as arg to function is not yet supported. It's in my todo list :)

To simulate passing custom types by ref, you can pass the address of the custom type to the function as a nat, and peek/poke or peekw/pokew (depending on the member type) at address+member offset by hand in the function. Not ideal but it should work (I did not test it yet).
The following user(s) said Thank You: ludojoey

Please Log in or Create an account to join the conversation.

More
5 days 7 hours ago #175 by ludojoey
Thanks for your reply!
Yes, I thought to do this, but not very readable..

Well, I will use an array of global variable and will pass the index to work with.
 

Please Log in or Create an account to join the conversation.

Time to create page: 0.165 seconds
Powered by Kunena Forum