Page 1 of 1

How to pass array as parameter to macro

Posted: Tue Oct 16, 2018 3:32 pm
by Steven_SS
Hello!
I need help on passing an array as a parameter. It seems real simple, but I can't figure it out on flowcode at the moment. The array is set as a global byte msg[255].
I have one call needing to go as "crc_out(msg[], timeout, true)" but I cant get the array(msg[]) to pass.

Then the next should go as "crc = CalcCRC(msg_len + 2, &msg[1])" but the "&msg[1]" wont go through. Neither would "msg[1]" if I tried.
And finally, the CalcCRC macro should read in those parameters as "crc = CalcCRC(LEN, *u8Buf)".

How can I make flowcode macros understand passing arrays or address/pointer of arrays through?? Please help and thank you in advance.

Re: How to pass array as parameter to macro

Posted: Tue Oct 16, 2018 4:56 pm
by Benj
Hello,

Here's an example.
ArrayDemo.fcfx
(6.37 KiB) Downloaded 394 times
If you're still having trouble then please post what you have so far then we might be able to help directly with your project file.

Re: How to pass array as parameter to macro

Posted: Tue Oct 16, 2018 5:13 pm
by Steven_SS
Thank you! That does help, but not quite. I'll send the project over in a private message.
Thanks again Benj!

-Steven

Re: How to pass array as parameter to macro

Posted: Tue Oct 16, 2018 5:23 pm
by Benj
I think I see what you need you're trying to pass a sub part of an array.

Flowcode won't currently let you do this so you might have to do it like this.

CalcCRC(MsgLength, DataArray, ArrayOffset)

The ArrayOffset basically tells you to start from location 1 of the data array.


Arduino uses arrays all over the place to work with their C++ philosophy and avoid variable naming clashes when using multiple instances of a library.

With Flowcode you can simply have a global array and access this globally, this will significantly cut down on all the overhead of passing arrays around as parameters. Flowcode components allow the variable to get intelligently renamed so there won't be a clash. Therefore Arduino hacks are not required in Flowcode. Whenever I'm porting an Arduino library to a Flowcode component I get rid of any arrays as parameters and simply have a global array. This also gets away from the user having to create the unique array to drive the component, the variables required by the component are supplied by the component.

Re: How to pass array as parameter to macro

Posted: Tue Oct 16, 2018 5:48 pm
by Steven_SS
I definitely understand that Benj! We just figured that out as well. So that gets rid of the first issue. Thank you on that. I believe the 2 & 3 go together with address/pointer.