Macro calling

For general Flowcode discussion that does not belong in the other sections.
mnfisher
Valued Contributor
Posts: 2151
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 174 times
Been thanked: 994 times

Re: Macro calling

Post by mnfisher »

A few thoughts.....

I did a simple example - that allows macros with names 'A' to 'Z' - note that if you want to use lower case - you can either alter the call to .c - 'a' (instead of (.c - 'A')) - or convert the lower case letter to upper case.
I use a sparse array of 26 function pointers (0..25) - this could be extended (for example fn_table[128] then call fn_table['A']( ))

I added a small macro CallString that calls each character of a string passed as an argument in turn - there a couple of examples. Note that 'undefined' macros - are ignored (I threw an 'E' into one of the strings)
for example CallString("ABCDABCDZ") or CallString(.cmd_string)

The function table is initialised in supplementary code....

Code: Select all

typedef void (*function)();
function fn_table[26] = {
[0] = FCM_A,
[1] = FCM_B,
[2] = FCM_C,
[3] = FCM_D,
['Z' - 'A'] = FCM_Z};  // I handle 'A' to 'Z' as 0..25
It is necessary to get the addresses of the functions (Flowcode (C) is a compiled language and functions are called with 'call fn_address' at runtime (not call "function_name"))

I would recommend giving functions (and variables) meaningful names rather than single characters - but in this instance it is quicker to do it this way (storing a string of each function name and then searching would add overhead at runtime)

The function signature could be altered to allow arguments to be passed (or a value returned by the macros)

Martin
Attachments
macro_table_2.fcfx
(14.01 KiB) Downloaded 14 times

medelec35
Valued Contributor
Posts: 2375
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 755 times
Been thanked: 814 times

Flowcode v9 Re: Macro calling

Post by medelec35 »

Hi.
I have use a string array so you can use different string macro names rather than sticking to 1 character.
Flowchart does fully simulate.
I did nest them which made it look neater, but its more difficult to follow.
Un-nested decision branches just for the demo
Attachments
Macro Table Demo.fcfx
(13.56 KiB) Downloaded 6 times
Martin

Post Reply