Passing sub-arrays

Technical questions regarding the XTC tools and programming with XMOS.
Post Reply
User avatar
skoe
Experienced Member
Posts: 94
Joined: Tue Apr 27, 2010 10:55 pm
Contact:

Passing sub-arrays

Post by skoe »

I try to port an old parser from C to XC, so I can use the channel stuff directly in the same source code.

How to do following in XC (simplified scenario)?

Code: Select all

/* parse "foo 123" */
if (strcmp(cmd, "foo ") == 0)
    val = atoi(cmd + 4);
Yes, this is really simplified, but it shows what I want to do: Give a sub-array (here: substring) to a function without copying something.

Regards,
Thomas


kster59
XCore Addict
Posts: 162
Joined: Thu Dec 31, 2009 8:51 am

Post by kster59 »

Can't you just pass myVar[4] ?
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

Currently XC has no simple way of passing a slice of an array to another function. I would suggest modifying the function you are calling to take an additional parameter which is the offset from the base of the array it should start from. If you are unable to modify the function you could add C wrapper functions which take the array and offset pair and call the real function after doing the necessary address arithmetic.
User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm
Contact:

Post by Folknology »

Array slicing a la python would be a wonderful feature to add to XC by the way, given the lack of pointers.
User avatar
skoe
Experienced Member
Posts: 94
Joined: Tue Apr 27, 2010 10:55 pm
Contact:

Post by skoe »

Thank you for the comments, a C wrapper must help once more :)

Yes, there are still many ideas to make XC even better for everyday use. But since it is so easy to mix XC/C/Asm fortunately every problem can be solved obviously.
Post Reply